我正在使用cakephp 2.3.0并使用ACL。我按照以下方式向小组授予许可:
$group->id = 2;
$this->Acl->deny($group, 'controllers');
$this->Acl->allow($group, 'controllers/Posts');
现在如何从同一个控制器检查$ group-> id = 2的“控制器/帖子”?
我正在尝试
$this->Acl->check('controllers/Posts', '2');
但它总是返回false并生成警告:
Failed ARO/ACO node lookup in permissions check. Node references:
Aro: controllers/Pages
Aco: Data entry operator
请帮帮我。感谢。
答案 0 :(得分:2)
<强>语法强>
$this->Acl->check(array(
'model' => 'ModelName', # The name of the Model to check agains
'foreign_key' => $foreign_key # The foreign key the Model is bind to
), 'Controller/action'); # The controller and action to check the permissions for
导致以下调用:
作为用户
$this->Acl->check(array(
'model' => 'User',
'foreign_key' => $userId
), 'Posts/index');
作为一个群组
$this->Acl->check(array(
'model' => 'Group',
'foreign_key' => $groupId
), 'Posts/index');
我把它写下来包括一些可读性的换行符。
更多信息:
答案 1 :(得分:0)
检查节点权限与设置该权限非常相似,即
$group->id = 2;
$this->Acl->check($group, 'controllers/Posts');