doujia3441 2012-04-30 06:20
浏览 54
已采纳

CakePHP ACL教程initDB函数警告

I am following http://book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl-controlled-application/part-two.html tutorial and I got a bit slightly different groups (group 4 and 5) 4 is visitors and 5 is admins

    function initDB() {
 10         $group = $this->User->Group;
 11         //Allow admins to everything
 12         $group->id = 5;      
 13         $this->Acl->allow($group, 'controllers');
 14        //^doesnt work
 15        //$this->Acl->allow(array( 'model' => 'Group', 'foreign_key' => 5), 'controllers');
 16        
 17        
 18         $group->id = 4;
 19         $this->Acl->deny($group, 'controllers');
 20         $this->Acl->allow($group, 'controllers/User/login');
 21         $this->Acl->allow($group, 'controllers/User/logout');
 22        /*
 23        $this->Acl->deny(array( 'model' => 'Group', 'foreign_key' => 4), 'controllers');
 24        $this->Acl->allow(array( 'model' => 'Group', 'foreign_key' => 4), 'controllers/User/login');
 25        $this->Acl->allow(array( 'model' => 'Group', 'foreign_key' => 4), 'controllers/User/logout');
 26 */      
 27         
 28         
 29         echo "all done";
 30         exit();
 31     }

but when I run this function I get the following errors

Warning (512): DbAcl::allow() - Invalid node [CORE/Cake/Controller/Component/AclComponent.php, line 387]
Warning (512): DbAcl::allow() - Invalid node [CORE/Cake/Controller/Component/AclComponent.php, line 387]all done

what gives?!

edit - my App Controller looks like this

<?php

class AppController extends Controller {
    public $components = array(
            'Acl',
            'Auth' => array(
                'authorize' => array(
                    'Actions' => array('actionPath' => 'controllers')
                    )   
                ),  
            'Session'
            );  
    public $helpers = array('Html', 'Form', 'Session');

    public function beforeFilter() {
        $this->Auth->actionPath = 'controllers/';
        //Configure AuthComponent
        $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
        $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
        $this->Auth->loginRedirect = array('controller' => 'images', 'action' => 'index');
        $this->Auth->allow('display');
    }   
}


?>

EDIT 2: Full Warning looks like this

Warning (512): DbAcl::allow() - Invalid node [CORE/Cake/Controller/Component/AclComponent.php, line 387]
Code Context
DbAcl::allow() - CORE/Cake/Controller/Component/AclComponent.php, line 387
AclComponent::allow() - CORE/Cake/Controller/Component/AclComponent.php, line 128
UsersController::initDB() - APP/Controller/UsersController.php, line 20
ReflectionMethod::invokeArgs() - [internal], line ??
Controller::invokeAction() - CORE/Cake/Controller/Controller.php, line 473
Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 107
Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 89
[main] - APP/webroot/index.php, line 96

Let me know if you want me to post up any other code.

  • 写回答

1条回答

  • dongtiao1817 2012-05-04 10:13
    关注

    According to the warning, and to the fact you're calling 3 times $this->Acl->allow() and once $this->Acl->deny() but seem to get only 2 warnings, I assume that the lines that give a warning are the following:

    $this->Acl->allow($group, 'controllers/User/login');
    $this->Acl->allow($group, 'controllers/User/logout');
    

    I don't use AclExtras to synchronize the acos table with the existing actions, but AFAIK when checking the permissions the AclComponent requires the controller aliases in the acos table to be pluralized. So I assume that your acos table doesn't contain any record with alias User but a record with alias Users.

    This would explain why you don't have any node in your acos table that can be identified by 'controllers/User/login' nor by 'controllers/User/logout'.

    If my assumptions are correct, the following code would work:

    $this->Acl->allow($group, 'controllers/Users/login');
    $this->Acl->allow($group, 'controllers/Users/logout');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘