Reputation: 1211
is there an easy way to access the url helpers from the models like the ones available in the controllers
i mean in the controllers there is an easy way to generate urls like this :
$this->_helper->url(controller,action,null,params);
now what i need is an easy way to pass urls direclty from the model to the views , for now what i am doing is to pass the CONTROLLER,ACTION AND PARAM as an array to controller then replace the text in the controller with with the helper url in the controller but i want a better way is there one?
Upvotes: 0
Views: 6026
Reputation: 138
You can access the url helper by calling it directly:
$urlHelper = new Zend_View_Helper_Url();
$urlHelper->url(array(),'',true);
Upvotes: 7
Reputation: 4051
I found the following code snippet in a book, it maybe of help to someone:
$urlHelper = $this->_helper->getHelper('url');
$urlHelper->url(array(
'controller' => 'customer' ,
'action' => 'save'
),
'default'
);
Upvotes: -2
Reputation: 1211
actually it's a bit specific to my problem but i made work it this way
$check['msg'] == will contain the error or success message
from the models i pass the link that causes the problem
$messages['link'] = array('action'=>'index','controller'=>'trip','params'=>$tripid );
an on the controllers
$check['msg'] = str_replace('%link%',$this->_helper->url($check['link']['action'],$check['link']['controller'],null,array('id' => $check['link']['params'])),
$check['msg']);
$this->_flashMessenger->addMessage($check['msg']);
Upvotes: 0
Reputation: 316959
The Model should not access the View, nor having to know about it.
If you have to do work that is related to the presentation layer, either use an Action Helper or a View Helper. The data you are processing is fully available in the Controller, so there should be no need to pass it from model.
Upvotes: 1