gpt4 book ai didi

php - CakePHP ACL 教程 initDB 函数警告

转载 作者:行者123 更新时间:2023-12-04 18:22:29 25 4
gpt4 key购买 nike

我关注 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 //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 }

但是当我运行此功能时,出现以下错误
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

是什么赋予了?!

编辑 - 我的 App Controller 看起来像这样
<?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');
}
}


?>

编辑2:
完整警告看起来像这样
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

如果您希望我发布任何其他代码,请告诉我。

最佳答案

根据警告,以及您调用 3 次的事实 $this->Acl->allow()一次$this->Acl->deny()但似乎只收到 2 个警告,我假设发出警告的行如下:

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

我不使用 AclExtras 将 acos 表与现有操作同步,但 AFAIK 在检查 AclComponent 的权限时要求 acos 表中的 Controller 别名是复数形式。所以我假设您的 acos 表不包含任何别名为 User 的记录但是一条别名为 Users 的记录.

这可以解释为什么您的 acos 表中没有任何可以由 'controllers/User/login' 识别的节点。也不是 'controllers/User/logout' .

如果我的假设是正确的,那么以下代码将起作用:
$this->Acl->allow($group, 'controllers/Users/login');
$this->Acl->allow($group, 'controllers/Users/logout');

关于php - CakePHP ACL 教程 initDB 函数警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10379335/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com