Webmaster's Community
Designing and Development => Open Source => Yii PHP Framework Support => Topic started by: Savera on September 11, 2012, 12:27:22 PM
-
I am learning YII , they already given us demo webapp . How do I create my own user and then use those values to login to admin panel provided by Yii in their demo or webapp default setup ?
I am trying to read their documentation but it is not clear, I am looking for something which is easy , straightforward and explained with clarity and keeping in mind that even newbie can understand those documentation.
-
For login With database user and password you have to change useridentity.php authenticate mehtod and configure your Main.php also .
-
For login With database have to change useridentity.php authenticate mehtod and .
change authenticate mehtod like this.........
public function authenticate() {
$user = User::model()->findByAttributes(array('username' => $this->username));
if ($user === null) {
$this->errorCode = self::ERROR_USERNAME_INVALID;
} else {
if ($user->password !== $this->password) {
$this->errorCode = self::ERROR_PASSWORD_INVALID;
} else {
$this->_id = $user->id;
$this->errorCode = self::ERROR_NONE;
}
}
return !$this->errorCode;
}
public function getId() {
return $this->_id;
}
and change your main.php in config like this.........
// application components
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
-
Where i have to change if i want to login with email and password apart from user name please give the code for that Thanks in Advance
-
Hey if you want to login with email you can simply channge
$user = User::model()->findByAttributes(array('username' => $this->username)); to
$user = User::model()->findByAttributes(array('email' => $this->username)); or whatever column name you have in you database .
-
i m also agree with php developer this is nice trick to login with username or email also.
that is what i am looking for .
Thank you Very much