Question

Is there any reason why this code would time-out or not work in an action helper preDispatch() function or a plugin preDispatch() function?

$request =$this->getActionController->getRequest();
$request->setModuleName('default');
$request->setControllerName('auth');
$request->setActionName('login');
$request->setDispatched(false);

I am trying to implement an Zend_Acl redirection\forward so a guest user would be sent to a login prompt. Everything works fine until we arrive at this particular code snippet, then it times-out. I was following @RobAllens example in his book "Zend Frameworks in Action" on implementing Zend_Auth and Zend_Acl. The problem is just with this code snippet. I have tried it on both an action helper class and on plugin class with the same time-out error. It works fine on action method().

Was it helpful?

Solution

Because you are setting setDispatched(false), (I think) the action helper will be reinitialised for your login method, and so your ACL check will be run again. Since the condition will fail once more, ZF will again do an internal redirect to the login method, and the process repeats (hence infinite loop). The simplest fix is to add an additional condition so the check doesn't run for the login method itself:

if (!$this->_acl->isAllowed($role, $resource, $priv) && $request->getActionName() != 'login') {
    [...]
}

If this doesn't work, see if commenting out the setDispatched check makes any difference.

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