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.

php
douyan3478
douyan3478 我删除了它。仍然得到运行initDB的相同警告,当我尝试登录时,它不会将我重定向到任何地方,只是停留在该页面上。(我猜这是因为initDB给了我警告)。我应该发布的任何其他代码?
大约 8 年之前 回复
dongling3243
dongling3243 你可以删除$this->Auth->actionPath='controllers/';来自beforeFilter方法的这一行再试一次。
大约 8 年之前 回复
doubei8168
doubei8168 我添加了完整的警告..检查出来
大约 8 年之前 回复
duanqiang2977
duanqiang2977 是group_id4是组访问者group_id5是组管理员
大约 8 年之前 回复
dpruwm6206
dpruwm6206 你验证了你在initDB方法中提到的group_id是否存在?
大约 8 年之前 回复
douhoushou8385
douhoushou8385 当我尝试登录时,它不会重定向,也没有任何反应。我仍然可以访问图像(也就是帖子)链接但是当我尝试删除帖子或上传新图像时,它会要求我登录(就像它应该)但是当我尝试登录时,它什么都不做。
大约 8 年之前 回复
dongliu5475
dongliu5475 你试过登录并访问模块吗?是否工作正常,因为警告只是尝试它是否正常工作?
大约 8 年之前 回复
doulang9953
doulang9953 我已将代码更新为我的实际代码。
大约 8 年之前 回复
dongtan7418
dongtan7418 是的,我做到了!
大约 8 年之前 回复
drgmszo076956
drgmszo076956 你安装了AclExtras插件并运行./Console/cakeAclExtras.AclExtrasaco_sync命令吗?
大约 8 年之前 回复

1个回答



根据警告,以及您正在调用3次 $ this-&gt; Acl-&gt; allow的事实 ()</ code>和一次 $ this-&gt; Acl-&gt; deny()</ code>但似乎只得到2个警告,我假设发出警告的行如下:</ p>

  $ this-&gt; Acl-&gt; allow($ group,'controllers / User / login'); 
$ this-&gt; acl-&gt; allow($ group ,'controllers / User / logout');
</ code> </ pre>

我不使用AclExtras将acos表与现有操作同步,但在检查权限时使用AFAIK AclComponent要求acos表中的控制器别名为复数。 所以我假设您的acos表不包含别名为 User </ code>的记录,而是包含别名 Users </ code>的记录。</ p>

这样会 解释为什么你的acos表中没有任何节点可以通过'controllers / user / login'</ code>或'controllers / User / logout'</ code>来识别。< / p>

如果我的假设是正确的,以下代码将起作用:</ p>

  $ this-&gt; Acl-&gt; allow($ group,  'controllers / Users / login'); 
$ this-&gt; Acl-&gt; allow($ group,'controllers / Users / logout');
</ code> </ pre>
</ div>

展开原文

原文

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

dragon_9000
dragon_9000 这些路径导致控制器中的操作。 在Cake中,控制器的名称由复数模型名称(用户模型的UsersController)组成。 我想它遵循相同的逻辑。 谢谢你顺便接受了我的回答:-)
大约 8 年之前 回复
doufangyan6862
doufangyan6862 你是对的! 为什么它会使用用户而不是用户?
大约 8 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问