所以我有以下关系:
用户:
<?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