CakePHP 2.0.x: ACL: Multiple Groups?

I know this question has been asked before, but I don’t know if CakePHP 2.0.x was specifically asked. I could not find any information about whether the user can be part of several groups, now it is possible with the ACL component. I have never used an ACL component with CakePHP 1.3.x because it confused me. If it’s better now, I’d like to use it so as not to reinvent the wheel while rolling on my own. Any help would be appreciated.

+5
source share
1 answer

I have not tested it or have not used it before, but I can present one way:

You have a model Userand a model Group, and User HATBM GroupShaz Amjad notes.

At the moment when you perform your access control, select the list of all groups to which the user belongs (possibly using bindModel).

Then, something like:

$permits = array();
foreach ($thisUsersGroups as $group) {
   $permits[] = $this->Acl->check($group, 'myclass', 'update')
}

If it $permitscontains at least one true, they must be allowed.

There may be a better or more automatic way to do this, but I do not see that this should not work in principle.

0
source

All Articles