views:

286

answers:

1

I'm using several response segments which I push on my action stack like this:

$userlogAction = clone($request);
$userlogAction->setActionName('userlog')->setControllerName('index');
$actionStack->pushStack($userlogAction);

Now when I test for the current action in my view:

$request = Zend_Controller_Front::getInstance()->getRequest();
$action = $request->getActionName();

I get the name of one (random?) action but I want to test for another.

How can I test if a certain action is among the actions on the stack as opposed to just getting the last one on the stack?

+1  A: 

The request returned from Zend_Controller_Front::getRequest() is certainly not random but the request that the dispatcher is currently processing, ie. the request that caused your action controller's action method to be invoked and thus your view script to be executed. Using the action stack plugin, you just add more requests to process one by one by the dispatcher.

If you want to get all the requests that are on the action stack, you have to query the action stack plugin directly:

<?php
$front = Zend_Controller_Front::getInstance();
$plugin = $front->getPlugin('Zend_Controller_Plugin_ActionStack');

if ($plugin) {
    $stack = $plugin->getStack();

    foreach ($stack as $request) {
        $action = $request->getActionName();
        // Do whatever you want with $action
    }
} else {
    // Not using the action stack
    $action = $front->getRequest()->getActionName();
}
?>
Ferdinand Beyer