2014-06-17 72 views
2

user.php的AclNode ::節點() - 找不到

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

通過識別阿羅節點 「陣列([Aro0.model] =>用戶[Aro0.foreign_key] =>)」類用戶延伸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上已經GOOGL

編輯和發現什麼都不能幫助我。

始終得到了錯誤:AclNode ::節點() - 無法找到鑑定阿羅節點 「陣列([Aro0.model] =>用戶[Aro0.foreign_key] =>)」

相信不知怎的,組的ForeignKey沒有被設置...但我找不到設置它的位置。

回答