2012-09-28 74 views
0

我想在Yi创建一个登录模块,但是我有这个错误,我真的不明白这是什么,因为我完全是Yii的初学者。请告诉我它是什么问题,解决这个问题。登录模块错误 - 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 

回答

2

更换$这个 - >电子邮件$这个 - >用户名在UserIdentity.php

+0

它的工作。谢谢:) –

+1

这是为什么工作?我改变了它,以便用户使用他/她的电子邮件登录...为什么我们不需要更改用户身份用户名字段?它是@param2 – surfer190