如何从ZF中的任何动作中调用多个控制器动作? [英] how to call multiple controller action from within any action in ZF?

查看:85
本文介绍了如何从ZF中的任何动作中调用多个控制器动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控制器动作,我希望在执行任何动作后执行它.我已经用这种方法编写了一个动作助手:

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?

推荐答案

您可以创建一个插件,例如:

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

    }
}

因此,将所需的动作放到此插件中,这些aciotns毕竟将被执行.

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

这篇关于如何从ZF中的任何动作中调用多个控制器动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆