Unable to Get CakePHP Cookbook Simple ACL Example

2019-08-29 03:07发布

问题:

I'm having problems getting ACL working with CakePHP. I've been working with the CakePHP Cookbook 2.0 example Simple Acl controlled Application, and have gone through the steps twice, but I've run into the same problem both times.

Everything appears to be setup correctly.

  • I'm able to create my groups, and users.
  • The aros table appears to have the same rows shown in the example on the web.
  • The acos and aros_acos tables appear to get populated with values that resemble the article.
  • And when I visit a page that's setup to be protected, I'm presented with the login page.

But when I login using the account I created, I see the following error:

Warning (512): DbAcl::check() - 
Failed ARO/ACO node lookup in permissions check.  Node     references:
Aro: Array
(
[User] => Array
    (
        [id] => 1
        [username] => dc
        [email] => myemail@somedomain.com
        [group_id] => 1
        [created] => 2011-10-27 14:58:59
        [modified] => 2011-10-27 14:58:59
    )
)  
Aco: /Posts/add [CORE/Cake/Controller/Component/AclComponent.php, line 303]

That account is setup as an administrator, and the administrator group has been granted access to everything ... so if it works, I shouldn't have a problem ... but it seems like there's a lower-level problem that's getting in my way. I can post my DB tables as well if that'd be helpful, but figured I'd start here. Thanks for any insight you can provide.

回答1:

The documentation was updated to address this issue. If you add this in the beforeFilter method in AppController it resolves the problem.

$this->Auth->authorize = array(
    AuthComponent::ALL => array('actionPath' => 'controllers'),
    'Actions',
);


回答2:

Add $this->Auth->allow('initDB'); in beforeFilter()



标签: php cakephp acl