The question is about the router's setDispatched() method of Zend Framework...
I have a fooAction()
and a loginAction()
in the same controller (the indexController).
I also have an ActionHelper
and I'm using it's preDispatch()
method. At the end of this function I have an if
statement where I check the ACL:
public function preDispatch() {
// some code...
if (!$this->_acl->isAllowed($role, $resource, $privilege)) {
$request->setModuleName('default');
$request->setControllerName('index');
$request->setActionName('login');
$request->setDispatched(false); //what does this mean exactly??
}
}
So when I want to reach fooAction()
, and the user hasn't got the permission, I set the Action name to 'login'...
Now my question is: what does the $request->setDispatched(false);
mean exactly?
Does it indicate that ZF can start to dispatch the loginAction() because it hasn't been dispatched yet (setDispatched(false);)?
From Zend Framework's Reference Guide:
At the beginning of each iteration, it sets a flag in the request object indicating that the action has been dispatched. If an action or pre or postDispatch plugin resets that flag, the dispatch loop will continue and attempt to dispatch the new request. By changing the controller and/or action in the request and resetting the dispatched flag, the developer may define a chain of requests to perform.
By calling setDispatched(false)
you're basically saying that the request wasn't sent to the controller yet, and the Dispatcher will attempt to re-despatch it. This is necessary because you're changing the module, controller and action of the request and you want the Dispatcher to process it again and send it to the right place.