Question

i have a plugin for frontcontroller.

it work fine for dispatcherloodstartup metod , 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_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 bootsrap code:

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

if i must use of stackpush , wich number is useful?

Was it helpful?

Solution

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.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top