views:

48

answers:

3

hi all,

i have a controller action and i want it to be execute 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?

thx in advance.

A: 

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

zwip
so, how do i solve this problem?
rahim asgari
+1  A: 

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

racetrack
+ 1 Move the logic to your helper and your problem will be solved.
Keyne
could u give me a sample code please. i dont want to use actionstack helper in my actions. because this way i have to write it in every controller action.
rahim asgari
No you don't have to write it in every controller action, only in `preDispatch()`. You can also write a Controller plugin.
racetrack
A: 

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.

Keyne