gpt4 book ai didi

php - CakePHP AclNode::node() - 找不到已识别的 Aro 节点

转载 作者:行者123 更新时间:2023-12-02 21:50:08 25 4
gpt4 key购买 nike

所以我有以下关系:

用户:

    <?php
App::uses('AppModel', 'Model');
/**
* User Model
*
* @property Roles $Roles
*/
class User extends AppModel {
public $actsAs = array('Acl' => array('type' => 'requester'));
public $belongsTo = array('Role');

public function parentNode() {
if (!$this->id && empty($this->data)) {
return null;
}
if (isset($this->data['User']['role_id'])) {
$roleId = $this->data['User']['role_id'];
} else {
$roleId = $this->field('role_id');
}
if (!$roleId) {
return null;
} else {
return array('Role' => array('id' => $roleId));
}
}
/**
* Display field
*
* @var string
*/
public $displayField = 'username';


public function beforeSave($options = array()) {
$this->data['User']['password'] = AuthComponent::password($this->data['User']['password']);
return true;
}

//The Associations below have been created with all possible keys, those that are not needed can be removed

/**
* belongsTo associations
*
* @var array
*/
}

角色:

    <?php
App::uses('AppModel', 'Model');
class Role extends AppModel {
public $actsAs = array('Acl' => array('type' => 'requester'));
public function parentNode() {
return null;
}

public $displayField = 'name';

}

我已经在数据库中设置了 Aro 和 aco 表。现在,当我尝试添加用户时,我收到以下错误消息:

AclNode::node() - Couldn't find Aro node identified by "Array ( [Aro0.model] => Role [Aro0.foreign_key] => 1 ) "

我觉得我已经尝试了一切。

有谁知道为什么会这样吗?

我的保存逻辑(添加操作):

        public function add() {
if ($this->request->is('post')) {
$this->User->create();
if ($this->User->saveAll($this->request->data)) {
$this->Session->setFlash(__('The user has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
}
}
$roles = $this->User->Role->find('list');
$this->set(compact('roles'));
}

错误消息和堆栈跟踪:

    2013-09-13 14:28:56 Error: [CakeException] AclNode::node() - Couldn't find Aro node identified by "Array
(
[Aro0.model] => Role
[Aro0.foreign_key] => 1
)
"
Request URL: /udlejnings-priser/cake/users/add
Stack Trace:
#0 /var/www/udlejnings-priser/cake/lib/Cake/Model/Behavior/AclBehavior.php(92): AclNode->node(Array)
#1 /var/www/udlejnings-priser/cake/lib/Cake/Model/Behavior/AclBehavior.php(110): AclBehavior->node(Object(User), Array, 'Aro')
#2 [internal function]: AclBehavior->afterSave(Object(User), true, Array)
#3 /var/www/udlejnings-priser/cake/lib/Cake/Utility/ObjectCollection.php(132): call_user_func_array(Array, Array)
#4 [internal function]: ObjectCollection->trigger(Object(CakeEvent))
#5 /var/www/udlejnings-priser/cake/lib/Cake/Event/CakeEventManager.php(248): call_user_func(Array, Object(CakeEvent))
#6 /var/www/udlejnings-priser/cake/lib/Cake/Model/Model.php(1789): CakeEventManager->dispatch(Object(CakeEvent))
#7 /var/www/udlejnings-priser/cake/lib/Cake/Model/Model.php(2270): Model->save(Array, Array)
#8 /var/www/udlejnings-priser/cake/lib/Cake/Model/Model.php(2073): Model->saveAssociated(Array, Array)
#9 /var/www/udlejnings-priser/cake/app/Controller/UsersController.php(82): Model->saveAll(Array)
#10 [internal function]: UsersController->add()
#11 /var/www/udlejnings-priser/cake/lib/Cake/Controller/Controller.php(490): ReflectionMethod->invokeArgs(Object(UsersController), Array)
#12 /var/www/udlejnings-priser/cake/lib/Cake/Routing/Dispatcher.php(187): Controller->invokeAction(Object(CakeRequest))
#13 /var/www/udlejnings-priser/cake/lib/Cake/Routing/Dispatcher.php(162): Dispatcher->_invoke(Object(UsersController), Object(CakeRequest), Object(CakeResponse))
#14 /var/www/udlejnings-priser/cake/app/webroot/index.php(110): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#15 {main}

我的帖子请求

    Data = {array}[1]
User = {array}[3]
username = test2
password = test
role_id = 1

蛋糕版本2.4.0

最佳答案

我遇到错误是因为 lft 和 rght 列为空。错过了在 cakephp Automated tool for creating ACOs manual 。通过运行控制台脚本解决了这个问题:

cake AclExtras.AclExtras recover aro

关于php - CakePHP AclNode::node() - 找不到已识别的 Aro 节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18786095/

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