Designing and Development > Yii PHP Framework Support

How to login using database in YII framework

(1/2) > >>

Savera:
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.

phpdeveloper:
For login With database user and password you have to change useridentity.php authenticate mehtod and configure  your Main.php also .

girish baghel:
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,
      ),




rahul:
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

phpdeveloper:
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 .

Navigation

[0] Message Index

[#] Next page

Go to full version