开发者

how run an action after executing the action of control (in all of the pages)

I have a plugin for frontcontroller.

It works fine for dispatcherloodstartup method, but postdispatcher can't call action!

What is wrong?

This is my plugin:

class Places_Controller_Plugin_ActionSetup extends Zend_Controller_Plugin_Abstract
{

public function dispatchLoopStartup( Zend_Controller_Request_Abstract $request)
    {
        $front = Zend_Controller_Front::getInstance();
        
        if (!$front->hasPlugin('Zend_Controller_Plugin_ActionStack')) {
                $actionStack = new Zend_Controller_Plugin开发者_StackOverflow中文版_ActionStack();
                $front->registerPlugin($actionStack, 97);
            } else {
            $actionStack = $front->getPlugin('Zend_Controller_Plugin_ActionStack');
        }
        
            $menuAction = clone($request);
            $menuAction->setActionName('menu')->setControllerName('index');
            $actionStack->pushStack($menuAction);
        
    }
     

    public function postDispatch(Zend_Controller_Request_Abstract $request)
    {     $menuAction = clone($request);
        $menuAction->setActionName('toolbar')->setControllerName('index');
    }
}

this is my bootstrap code:

$frontController->registerPlugin(new Places_Controller_Plugin_ActionSetup(), 98);

if I must make use of stackpush, which number is useful?


First. This is a bad practise. You have to do 3 dispatch roundabouts (all plugins pre- and post-dispatch, controllers pre&post, ...)- If possible I would switch to one front controller plugin, that will fill the appropriate layout variables and use partials/view helpers to render them.

The problem with your code is that in postDispatch() your request has already isDispatched = true, which means it won't be dispatched again. Option might be to create the request yourself. And then push it to the actionstack.

Also you can use actionstack methods $this->actionstack($action, $controller, $module, $params), that will create the request for you ;) You can get the current params like this $params = $frontController->getRequest()->getParams() or sth. like that (not 100% sure about the method name).

EDIT:

If you put the toolbar rendering into layout, then there is no problem. You can assign the variables to the view and they will be ready in layout. You'll just have echo $this->render('toolbar.phtml'); and that's all. It will always be rendered after all actions are rendered as layout is the last view rendered. Just make sure your toolbar variables don't collide with other variables (good idea is to refix them with something - say $this->toolbarUsername;$this->toolbarIsLogged, etc.)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜