开发者

how to access url helper in zend from the models

开发者 https://www.devze.com 2023-01-14 10:37 出处:网络
is there an easy way to access the url helpers from the models like the ones available in the controllers

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开发者_Python百科 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?


You can access the url helper by calling it directly:

$urlHelper = new Zend_View_Helper_Url();
$urlHelper->url(array(),'',true);


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.


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']); 


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'
        );
0

精彩评论

暂无评论...
验证码 换一张
取 消