how to call multiple controller action from within any action in ZF?

最后都变了- 提交于 2019-12-24 23:08:44

问题


I have a controller action and I want it to be executed after any action. I have written an action helper with this method:

public function postDispatch(){    
    $actionstack = Zend_Controller_Action_HelperBroker::getStaticHelper('actionStack');
    $actionstack->direct('myaction', 'mycontroller');
}

But it seems that it stuck in a loop, what is wrong with my code?


回答1:


You could create a Plugin, for example:

class Plugin_Sidebar extends Zend_Controller_Plugin_Abstract {

    public function postDispatch(Zend_Controller_Request_Abstract $request)
    {
        if($request->getModuleName() == 'admin')
        {
            return;
        }
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
        if (null === $viewRenderer->view) {
            $viewRenderer->initView();
        }
        $view = $viewRenderer->view;

        $yt = new Zend_Gdata_YouTube();
        $view->videos = $yt->getUserUploads('MysteryGuitarMan');

    }
}

So put the actions you want in this plugin and these aciotns will be executed after all.




回答2:


You can either use the ActionStack action helper, or simply put the logic of that method in your postDispatch()




回答3:


What happens is that the postDispatch is called again after mycontroller->myaction has been dispatched, so it calls mycontroller->myaction again and again.



来源:https://stackoverflow.com/questions/3423209/how-to-call-multiple-controller-action-from-within-any-action-in-zf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!