2

我正在构建一个基于配置文件的应用程序。我正在尝试使用此处找到的简单 acl 控制应用程序教程:http: //book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl-controlled-application/simple-acl-controlled-application。 html,创建我的组和权限。我在以不同用户身份登录时遇到了一些问题,以获得运行权限。我有一个管理员、经理和用户组。我已经设置了 ACO 和 ARO,并为每个组添加了权限。这是我的

class AppController extends Controller {

    public $components = array(
        'Acl',
        'Auth'=>array(
            'loginRedirect'=>array('controller'=>'users', 'action'=>'index'),
            'logoutRedirect'=>array('controller'=>'users', 'action'=>'index'),
            'authError'=>'You cannot access that page',
            'authorize'=>array('actionPath' => 'controllers')
        ),
        'Session'
    );

    public function isAuthorized($user) {
        return true;
    }

    public function beforeFilter() {
        $this->Auth->authorize = array(
            'Actions' => array(
                'userModel' => 'User',
                'actionPath' => 'users'
            )
        );

        $this->Auth->allow('display');

        $this->set('logged_in', $this->Auth->loggedIn());
        $this->set('current_user', $this->Auth->user());

    }

}

用户控制器.php

class UsersController extends AppController {

    public function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allow('view');
    }



    public function login() {
        if ($this->request->is('Post')) {
            if ($this->Auth->login()) {
                $this->redirect($this->Auth->redirect());
            } else {
                $this->Session->setFlash('Your username/password combination was incorrect');
            }
        }
    }

    public function logout() {
        $this->redirect($this->Auth->logout());
    }

我现在得到的错误是:

Warning (512): DbAcl::check() - Failed ARO/ACO node lookup in permissions check. Node references:
Aro: Array
Permission::check() - CORE/Cake/Model/Permission.php, line 94
DbAcl::check() - CORE/Cake/Controller/Component/Acl/DbAcl.php, line 73
AclComponent::check() - CORE/Cake/Controller/Component/AclComponent.php, line 109
ActionsAuthorize::authorize() - CORE/Cake/Controller/Component/Auth/ActionsAuthorize.php, line 40
AuthComponent::isAuthorized() - CORE/Cake/Controller/Component/AuthComponent.php, line 412
AuthComponent::startup() - CORE/Cake/Controller/Component/AuthComponent.php, line 336
ObjectCollection::trigger() - CORE/Cake/Utility/ObjectCollection.php, line 132
call_user_func - [internal], line ??
CakeEventManager::dispatch() - CORE/Cake/Event/CakeEventManager.php, line 248
Controller::startupProcess() - CORE/Cake/Controller/Controller.php, line 671
Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 184
Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 162
[main] - APP/webroot/index.php, line 109

由于某种原因,它无法访问权限。而且我似乎无法找到解决此问题的解决方案。任何帮助都会很棒!提前致谢!

4

2 回答 2

2

这些错误通常是因为您在控制器中添加了一个函数/方法,但您没有重新填充您的 acos 和 aros_acos 表。

你需要填充你的 acos 表

./Console/cake AclExtras.AclExtras aco_sync

http://book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl-controlled-application/part-two.html

填充后,我们需要将此新方法的权限分配给我们的 aros_acos 表

$this->Acl->allow($group, 'controllers/Posts/myNewCustomMethod');

然后再次运行 initDB 函数。教程一步一步讲得很清楚。

于 2013-06-21T07:25:03.200 回答
0

正在警告 msj,只是为了检查:将此行放在您的函数 beforeFilter 中以检查..如果没问题,只需关注您的权限..

public function beforeFilter() {
    parent::beforeFilter();
    // For CakePHP 2.0
    $this->Auth->allow('*');
    // For CakePHP 2.1 and up
    $this->Auth->allow();
    // or you can put the view
    $this->Auth->allow('index','edit','add','login','delete');
}
于 2015-06-27T21:53:19.440 回答