$this->add ( new Zend_Acl_Resource ( 'index' ) );
$this->addRole ( new Zend_Acl_Role ( 'guest' ) );
$this->allow('guest', 'index','view');
and i have problem in this condition
if (! $this->_acl->isAllowed ( $role, $resource, $action )){
... redirect to access denied
}
How can solve this problem?
You could check for the resource(action) to exist in the acl:
if(!$this->_acl->has($resource) || $this->_acl->isAllowed($role, $resource, $action))
Else could simply deny by default. If you then check for a non-existing action the acl will return false by default.
If you simply want to detect if a not-existing action is called from your controller, you can use the __call method of the controller.
For a more specific solution you should provide more information like where you perform the acl-check, how you setup your acl, ....
Example to catch not-existing actions in your controller:
My_Controller extends Zend_Controller_Action
{
__call($method, $args)
{
throw new Exception("Action does not exist"); // This is done by default
// Just do whatever you want to do in this function (like redirecting)
}
}
Anyway this could be done with the ErrorhandlerPlugin even without the magic function. As you only want to redirect to the error page you actually just have to take care, that the acl check doesn't throw any exceptions because a resource (or Action) isn't found. Depending on where you do your check you have several posibilities do do this but assuming every controller is one Resource and you do all add them this shouldn't be a problem.