Issue
I am using cakephp 2.3.0 and working with ACL. I am giving the permission to a group as follows:
$group->id = 2;
$this->Acl->deny($group, 'controllers');
$this->Acl->allow($group, 'controllers/Posts');
Now how can I check 'controllers/Posts' is allowed for $group->id = 2 from same controller?
I am trying
$this->Acl->check('controllers/Posts', '2');
but it always return false and generate warning:
Failed ARO/ACO node lookup in permissions check. Node references:
Aro: controllers/Pages
Aco: Data entry operator
Please help me. Thanks.
Solution
Syntax
$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
Which results in the following call:
As a User
$this->Acl->check(array(
'model' => 'User',
'foreign_key' => $userId
), 'Posts/index');
As a Group
$this->Acl->check(array(
'model' => 'Group',
'foreign_key' => $groupId
), 'Posts/index');
I wrote it down including some linebreaks for readability.
More info at:
- http://api.cakephp.org/2.3/class-AclComponent.html#_check
- http://api.cakephp.org/2.3/class-AclNode.html
- check permission against group not users using Auth->authorize="actions"
Answered By - Jelmer Answer Checked By - Senaida (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.