本文介绍了AclNode :: node() - 找不到由“Array([Aro0.model] => User [Aro0.foreign_key] =>)标识的Aro节点”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
User.php
User.php
App::uses('AuthComponent', 'Controller/Component');
class用户扩展AppModel {
class User extends AppModel {
public $primaryKey = 'usu_codigo';
public $foreignKey = 'usu_gru_codigo';
public $useTable = 'painel_usuario';
//public $recursive = 0;
public function beforeSave($options = array()) {
$this->data['User']['usu_senha'] = AuthComponent::password($this->data['User']['usu_senha']);
return true;
}
public $actsAs = array('Acl' => array(
'type' => 'requester',
'enabled' => true
));
public function parentNode() {
if (!$this->id && empty($this->data)) {
return null;
}
if (isset($this->data['User']['usu_gru_codigo'])) {
$groupId = $this->data['User']['usu_gru_codigos'];
} else {
$groupId = $this->field('usu_gru_codigo');
}
if (!$groupId) {
return null;
} else {
return array('Group' => array('id' => $groupId));
}
}
public $name = 'User';
public $validate = array(
'usu_email' => array(
'required' => array(
'rule' => 'notEmpty',
'required' => 'create'
),
'unique' => array(
'rule' => 'isUnique',
'required' => 'create'
),
'email' => array('rule' => 'email')
),
'usu_senha' => array(
'required' => array(
'rule' => 'notEmpty',
'required' => 'create'
),
'size' => array(
'rule' => array(
'minLength',
'8'
),
'message' => 'Minimum 8 characters long'
)
)
);
public $belongsTo = array(
'Group' => array(
'className' => 'Group',
'foreignKey' => 'usu_gru_codigo'
)
);
}
UsersController。 php
class UsersController extends AppController {
public function beforefilter() {
parent::beforeFilter();
$this->Auth->userModel = 'User';
$this->Auth->allow('add', 'logout');
}
public function isAuthorized() {
return true;
}
public function bindNode($user) {
return array(
'model' => 'Group',
'foreign_key' => $user['User']['usu_gru_codigo']
);
}
public function initDB() {
$group = $this->User->Group;
// Allow admins to everything
$group->id = 10;
$this->Acl->allow($group, 'controllers');
// allow basic users to log out
$this->Acl->allow($group, 'controllers/users/logout');
// we add an exit to avoid an ugly "missing views" error message
echo "all done";
exit;
}
public function index() {
$this->set('users', $this->User->find('all'));
}
public function add() {
$this->set('groups', $this->User->Group->find('list', array(
'fields' => array('gru_nome'),
'order' => array('gru_nome')
)));
if ($this->request->is('post')) {
$this->User->create();
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('Usuário adicionado com sucesso!'));
return $this->redirect(array('action' => 'login'));
}
$this->Session->setFlash(__('Não foi possível adicionar o usuário!'));
}
}
public function login() {
if ($this->request->is('post')) {
$q = $this->User->query('SELECT usu_codigo FROM painel_usuario WHERE usu_email = "' . $this->request->data['User']['usu_email'] . '" AND usu_senha = "' . AuthComponent::password($this->request->data['User']['usu_senha']) . '";');
$this->request->data['User']['usu_codigo'] = $q[0]['painel_usuario']['usu_codigo'];
if ($this->Auth->login($this->request->data)) {//o erro que estava dando era por que não estava passado o request->data com parâmetro
debug($this->request->data);
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash(__('Nome de usuário ou senha incorrestos!'));
}
}
}
public function logout() {
if ($this->Auth->logout()) {
$this->Session->setFlash(__("Adeus!"));
$this->redirect($this->Auth->redirect());
}
}
}
Group.php
class Group extends AppModel {
public $primaryKey = 'gru_codigo';
public $useTable = 'painel_grupo';
var $virtualFields = array(
'id' => 'gru_codigo',
'name' => 'gru_nome'
);
public $actsAs = array('Acl' => array('type' => 'requester'));
public function parentNode() {
return null;
}
}
GroupsController.php
<?php
class GroupsController extends AppController {
public function beforefilter() {
parent::beforeFilter();
$this -> Auth -> allow();
}
public function index() {
$this -> set('groups', $this -> Group -> find('all', array('order' => array('Group.gru_nome'))));
}
public function add() {
if ($this -> request -> is('post')) {
$this -> Group -> create();
if ($this -> Group -> save($this -> request -> data)) {
$this -> Session -> setFlash(__('Grupo criado com sucesso!'));
return $this -> redirect(array('action' => 'index'));
}
$this -> Session -> setFlash(__('Não foi possível criar o grupo!'));
}
}
}
总是出现错误: AclNode :: node() - 找不到Aro节点标识为Array [Aro0.model] => User [Aro0.foreign_key] =>)
相信某些情况下群组的ForeignKey未设置...
believe that somehow the ForeignKey of groups is not being set ... but I can not find where to set it.
推荐答案
您有 group_id
(当然有用户名和密码)列在你的数组,这是用于登录?我的意思是这行
Do you have group_id
(of course with username and password) column in your array, that is used to login ? I mean this line
$this->Auth->login($this->request->data))
$ this-> request-> data
应该包含像
array('username' => 'my_username', 'password' => 'password', 'group_id' => '1')
source:
这篇关于AclNode :: node() - 找不到由“Array([Aro0.model] => User [Aro0.foreign_key] =>)标识的Aro节点”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!