AclNode::node()-无法';t找到由“0”标识的Aro节点;数组([Aro0.model]=>;用


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

User.php

App::uses('AuthComponent', 'Controller/Component');

类用户扩展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!'));
        }
    }
}

在StackOverflow中已经搜索过了,没有找到任何可以帮助我的东西。

始终得到错误:AclNode::node((-找不到由"Array([Aro0.model]=>User[Aro0.foreign_key]=>("标识的Aro节点

相信不知何故,团体的ForeignKey没有被设定。。。但我找不到在哪里设置它。

您的数组中有用于登录的group_id列(当然还有用户名和密码(吗?我是说这条

$this->Auth->login($this->request->data))

$this->request->data应包含类似的数组

array('username' => 'my_username', 'password' => 'password', 'group_id' => '1')

来源:http://hashmode.com/aclnode-node-couldn-t-find-aro-node-identified-by-array-aro0-model-group-aro0-foreign_key-cakephp/30

如果一个用户的组被手动更改为另一个组,然后尝试更改属于同一组的用户的密码,则会发生此错误;恢复该用户的组或删除其组已手动更改的用户。问题将得到解决。