I have implemented database driven ACL functionality using controller plugin predispatch()
function.
我使用控制器插件predispatch()函数实现了数据库驱动的ACL功能。
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.
所以我的问题是如何使用predispatch()方法在单个插件中实现ACl和错误处理。
Any help please.
请帮忙。
3 个解决方案
#1
1
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
如果您需要特殊页面,则必须将accessAction放入错误控制器,或者您只需使用现有的errorAction
#2
1
You should set permission for error controller in your DB.
您应该在数据库中设置错误控制器的权限。
So current user(role id) should have permission to access the error controller.
因此,当前用户(角色ID)应具有访问错误控制器的权限。
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.
首先在资源表中插入,然后在权限表中插入。
#3
0
You should add your error controller to your ACL plugin by default for all users.
默认情况下,您应该将错误控制器添加到ACL插件中。
if (!$this->has('Default_Error')) {
$this->addResource('Default_Error');
$this->allow('guest', 'Default_Error');
}
This way everyone is allowed to see error controller.
这样每个人都可以看到错误控制器。
#1
1
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
如果您需要特殊页面,则必须将accessAction放入错误控制器,或者您只需使用现有的errorAction
#2
1
You should set permission for error controller in your DB.
您应该在数据库中设置错误控制器的权限。
So current user(role id) should have permission to access the error controller.
因此,当前用户(角色ID)应具有访问错误控制器的权限。
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.
首先在资源表中插入,然后在权限表中插入。
#3
0
You should add your error controller to your ACL plugin by default for all users.
默认情况下,您应该将错误控制器添加到ACL插件中。
if (!$this->has('Default_Error')) {
$this->addResource('Default_Error');
$this->allow('guest', 'Default_Error');
}
This way everyone is allowed to see error controller.
这样每个人都可以看到错误控制器。