CakePHP ACL教程initDB函数警告 [英] CakePHP ACL tutorial initDB function warnings

查看:180
本文介绍了CakePHP ACL教程initDB函数警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注 http://book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl-controlled-application/part-two.html 教程,我有一点略有不同的组(组4和5)4是访客,5是管理员

  function initDB(){
10 $ group = $ this- > User-> Group;
11 //允许admins to everything
12 $ group-> id = 5;
13 $ this-> Acl-> allow($ group,'controllers');
14 // ^ does not work
15 // $ this-> Acl-> allow(array('model'=>'Group','foreign_key'=> 5)控制器);
16
17
18 $ group-> id = 4;
19 $ this-> Acl-> deny($ group,'controlling');
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 echoall done;
30 exit();
31}

但是当我运行这个函数时,我得到以下错误

 警告(512):DbAcl :: allow() - 无效节点[CORE / Cake / Controller / Component / AclComponent.php,line 387] 
警告(512):DbAcl :: allow() - 无效节点[CORE / Cake / Controller / Component / AclComponent.php,line 387] all done

是什么??



编辑 - 我的应用程序控制器看起来像这样

 <?php 

类AppController extends Controller {
public $ components = array(
'Acl' ,
'Auth'=> array(
'authorize'=&array; array(
'Actions'=> array('actionPath'=>'controllers')

),
'Session'
);
public $ helpers = array('Html','Form','Session');

public function beforeFilter(){
$ this-> Auth-> actionPath ='controllers /';
//配置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');
}
}


?>

编辑2:
完整警告类似于

 警告(512):DbAcl :: allow() - 无效节点[CORE / Cake / Controller / Component / AclComponent.php,line 387] 
上下文
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,第20行
ReflectionMethod :: invokeArgs() - [internal],line?
Controller :: invokeAction() - CORE / Cake / Controller / Controller.php,第473行
Dispatcher :: _ invoke() - CORE / Cake / Routing / Dispatcher.php,第107行
Dispatcher :: dispatch() - CORE / Cake / Routing / Dispatcher.php,第89行
[main] - APP / webroot / index.php,第96行


解决方案

如果你想要我发布任何其他代码, div>

根据警告,以及你调用3次 $ this-> Acl-> allow()和一次 $ this-> Acl-> deny()但似乎只有两个警告,我假设给出警告的行如下:

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

我不使用AclExtras来同步acos表与现有操作,但AFAIK检查权限AclComponent需要将acos表中的控制器别名复数化。因此,我假设您的acos表不包含别名 User 的任何记录,但是包含别名 Users 的记录。 / p>

这将解释为什么你的acos表中没有可以通过'controllers / User / login''controllers / User / logout'



如果我的假设是正确的,代码将工作:

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


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.

解决方案

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');

这篇关于CakePHP ACL教程initDB函数警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆