PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, April 22, 2022

[FIXED] How to give node referance to check cakephp 2.3 ACL permission

 April 22, 2022     acl, cakephp, cakephp-2.3, php, user-permissions     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing