我正在尝试在 Yi 中创建一个登录模块,但是我遇到了这个错误,我真的不明白这是什么,因为我完全是 Yii 的初学者。请告诉我这是什么问题以及该问题的解决方案。
未定义属性“UserIdentity.Email”。
C:\wamp\www\topicoll\protected\components\UserIdentity.php(21)
09 {
10 /**
11 * Authenticates a user.
12 * The example implementation makes sure if the username and password
13 * are both 'demo'.
14 * In practical applications, this should be changed to authenticate
15 * against some persistent user identity storage (e.g. database).
16 * @return boolean whether authentication succeeds.
17 */
18 public function authenticate()
19 {
20
21 $users = TblUser::model()->find('Email=?',array($this->Email));
22 // $user= TblUser::User::model()->find('LOWER(Email)=?',array(strtolower($this->Email)));
23 if($users===null)
24 $this->errorCode=self::ERROR_USERNAME_INVALID;
25 else if(!$users->validatePassword($this->password))
26 $this->errorCode=self::ERROR_PASSWORD_INVALID;
27 else
28 {
29 $this->_id=$users->id;
30 $this->Email=$users->Email;
31 $this->errorCode=self::ERROR_NONE;
32 }
33 return $this->errorCode==self::ERROR_NONE;
Stack Trace
#0
– C:\wamp\www\topicoll\protected\components\UserIdentity.php(21): CComponent->__get("Email")
16 * @return boolean whether authentication succeeds.
17 */
18 public function authenticate()
19 {
20
21 $users = TblUser::model()->find('Email=?',array($this->Email));
22 // $user= TblUser::User::model()->find('LOWER(Email)=?',array(strtolower($this->Email)));
23 if($users===null)
24 $this->errorCode=self::ERROR_USERNAME_INVALID;
25 else if(!$users->validatePassword($this->password))
26 $this->errorCode=self::ERROR_PASSWORD_INVALID;
#1
– C:\wamp\www\topicoll\protected\models\LoginForm.php(45): UserIdentity->authenticate()
40 * This is the 'authenticate' validator as declared in rules().
41 */
42 public function authenticate($attribute, $params) {
43 if (!$this->hasErrors()) {
44 $this->_identity = new UserIdentity($this->Email, $this->password);
45 if (!$this->_identity->authenticate())
46 $this->addError('password', 'Incorrect username or password.');
47 }
48 }
49
50 /**
#2
+ C:\wamp\www\yii\framework\validators\CInlineValidator.php(43): LoginForm->authenticate("password", array())
#3
+ C:\wamp\www\yii\framework\validators\CValidator.php(197): CInlineValidator->validateAttribute(LoginForm, "password")
#4
+ C:\wamp\www\yii\framework\base\CModel.php(158): CValidator->validate(LoginForm, null)
#5
– C:\wamp\www\topicoll\protected\controllers\SiteController.php(110): CModel->validate()
105 {
106 $model->attributes=$_POST['LoginForm'];
107
108 // var_dump($model);
109 // validate user input and redirect to the previous page if valid
110 if($model->validate() && $model->login())
111 {
112 $this->redirect(array('site/login', 'email'=>$model->Email));
113
114 echo $model->Email;
115
#6
+ C:\wamp\www\yii\framework\web\actions\CInlineAction.php(50): SiteController->actionLogin()
#7
+ C:\wamp\www\yii\framework\web\CController.php(309): CInlineAction->runWithParams(array("r" => "site/login"))
#8
+ C:\wamp\www\yii\framework\web\CController.php(287): CController->runAction(CInlineAction)
#9
+ C:\wamp\www\yii\framework\web\CController.php(266): CController->runActionWithFilters(CInlineAction, array())
#10
+ C:\wamp\www\yii\framework\web\CWebApplication.php(276): CController->run("login")
#11
+ C:\wamp\www\yii\framework\web\CWebApplication.php(135): CWebApplication->runController("site/login")
#12
+ C:\wamp\www\yii\framework\base\CApplication.php(162): CWebApplication->processRequest()
#13
+ C:\wamp\www\topicoll\index.php(13): CApplication->run()
2012-09-28 07:22:44 Apache/2.2.21 (Win32) PHP/5.3.8 Yii Framework/1.1.10