嗨,我是 yii 框架的新手。我在提交登录详细信息后收到此错误。
错误
C:\wamp\www\yii\framework\web\auth\CWebUser.php(154)
152| $this->setState($name,$value);
153| else
154| parent::__set($name,$value);
155| }
在堆栈跟踪中
C:\wamp\www\yiiapp1\protected\models\LoginForm.php(71): CModule->__get("user")
70| $duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
71| Yii::app()->user->login($this->_identity,$duration);
72| return true;
这是我的 USER.PHP文件
class user extends CActiveRecord
{
public function validatePassword($password)
{
return CPasswordHelper::verifyPassword($password,$this->password);
}
public function hashPassword($password)
{
return CPasswordHelper::hashPassword($password);
}
public static function model($className=__CLASS__)
{
return parent::model($className);
}
public function tableName()
{
return 'user';
}
public function rules()
{
return array(
array('', 'safe', 'on'=>'search'),
);
}
public function relations()
{
return array(
);
}
public function attributeLabels()
{
return array(
);
}
public function search()
{
$criteria=new CDbCriteria;
return new CActiveDataProvider('user', array(
'criteria'=>$criteria,
));
}
}
登录表单
class LoginForm extends CFormModel
{
public $username;
public $password;
public $rememberMe;
private $_identity;
public function rules()
{
return array(
// username and password are required
array('username, password', 'required'),
// rememberMe needs to be a boolean
array('rememberMe', 'boolean'),
// password needs to be authenticated
array('password', 'authenticate'),
);
}
public function attributeLabels()
{
return array(
'rememberMe'=>'Remember me next time',
);
}
public function authenticate($attribute,$params)
{
if(!$this->hasErrors())
{
$this->_identity=new UserIdentity($this->username,$this->password);
if(!$this->_identity->authenticate())
$this->addError('password','Incorrect username or password.');
}
}
public function login($identity,$duration)
{
if($this->_identity===null)
{
$this->_identity=new UserIdentity($this->username,$this->password);
$this->_identity->authenticate();
}
if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
{
$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
Yii::app()->user->login($this->_identity,$duration);// --> HERE THE STACKTRACE SHOWING THE ERROR
return true;
}
else
return false;
}
}