Cakephp Auth问题:未定义的属性:User :: $ alias

时间:2011-02-11 09:35:35

标签: cakephp authentication

我现在一直在收到这个错误。

我一遍又一遍地搜索,但我无法得到答案。

可能我正在做些愚蠢的事。

这是我的环境;

UserController:

类UsersController扩展AppController {

    var $name = 'Users';
    var $components = array('Email');

    function login() {
    }

    function home() {
        pre('login oldunuz');
    }

    function logout() {
        $this->Session->setFlash(__('Goodbye!', true));
        $this->redirect($this->Auth->logout());
    }

    ....

}

AppController:   class AppController扩展了Controller {

    var $components = array('Session','Auth');
    function beforeFilter() {
        $this->Auth->loginError = 'You didnt supply valid identification.';
        $this->Auth->authError = 'You are not validated to see this location.';
        $this->Auth->allowedActions = array('register','confirm');
        $this->Auth->userScope = array('User.active' => 1);
    }
    function beforeRender() {
        $this->set('User', $this->Session->read('Auth.User'));
    }

}

的usermodel: class User扩展AppModel {     var $ name ='用户';     var $ displayField ='username';

var $validate = array(
    'username' => array(
        'notempty' => array(
            'rule' => array('notempty'),
            'message' => 'Username field can not be empty..',
        ),
        'u_unique' => array(
            'rule'=>array('isUnique'),
            'message' => 'The username you selected, is being used please choose another one.'
        )
    ),
    'email' => array(
        'email' => array(
            'rule' => array('email'),
            'message' => 'Please provide a valid email.',
        ),
        'e_unique' => array(
            'rule' => array('isUnique'),
            'message' => 'The email you selected, is being used please choose another one.'
        )
    ),
    ----

  /* if you want i send more of this code */

}

我不知道怎么解决这个问题, 但是为了帮助,cakephp说:

错误部分是:

if ($key == null)
{
    $model =& $this->getModel();
    return array($model->alias => $this->Session->read($this->sessionKey));
}

如果我制作$model->alias = "User"然后它可以工作但是在使用另一个$model->alias时,它会像以前一样爆炸,

我希望你有一个答案,谢谢大家,

0 个答案:

没有答案