Pregunta

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.

¿Fue útil?

Solución

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:

Otros consejos

checking a node permission is very similar to setting that permission ie

$group->id = 2;
 $this->Acl->check($group, 'controllers/Posts');
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top