I am trying to save the user but when I save I get the following error
AclNode::node() - Couldn't find Aro node identified by "Array ( [Aro0.model] => Role [Aro0.foreign_key] => ) "
I also get this error in the top
Undefined index: role_id [CORE\Cake\Model\AclNode.php, line 140]
I don't know what to do as when I added the roles it added them to aros with ease so why is it now giving me problem
I followed the guide provided by
which should be simple but it seems its not so simple.
In the Role Model
public $primaryKey = 'role_id';
public $displayField = 'role';
public $actsAs = array('Acl' => array('type' => 'requester'));
public function parentNode() {
return null;
}
In the User Model
public $primaryKey = 'user_id';
public $displayField = 'username';
public function beforeSave($options = array()) {
$this->data['User']['password'] = AuthComponent::password(
$this->data['User']['password']
);
return true;
}
public $hasMany = array(
'Role' => array(
'className' => 'Role',
'foreignKey' => 'role_id'
)
);
public $actsAs = array('Acl' => array('type' => 'requester'));
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));
}
}
My Save Code for User
public function add() {
//Populate roles dropdownlist
$data = $this->User->Role->find('list', array('fields' => array('role_id', 'role')));
$this->set('roles', $data);
if ($this->request->is('post')) {
$this->User->ContactDetail->create();
$this->User->ContactDetail->save($this->request->data);
$this->request->data['User']['contact_detail_id'] = $this->User->ContactDetail->id;
$this->User->Create();
if ($this->User->save($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.'));
}
}
}