I have implemented database driven ACL functionality using controller plugin predispatch()
function.
It's working fine. But it stopped requests to be sent on my error controller.
for example if specified controller / Action is not defined then system shows message "Access Denied" instead of showing "Request / Page not found".
So my question how can I implement both ACl and error handling in single plugin using predispatch()
method.
Any help please.
In your controller plugin, redirect to the error controller if necessary:
$request
->setModuleName('default')
->setControllerName('error')
->setActionName('access')
->setDispatched(true);
The accessAction has to be put into the error controller if you want a special page, or you can simply use the existing errorAction
You should set permission for error controller in your DB.
So current user(role id) should have permission to access the error controller.
I don't know you're structure of DB tables but in my way(probably is similar):
INSERT INTO "resources" ("id","name","description") VALUES (11,'error', 'Error controller');
INSERT INTO "permissions" ("role_id", "resource_id", "is_allowed") VALUES (1, 11, 't');
First insert in resource table and then in permission table.
You should add your error controller to your ACL plugin by default for all users.
if (!$this->has('Default_Error')) {
$this->addResource('Default_Error');
$this->allow('guest', 'Default_Error');
}
This way everyone is allowed to see error controller.