Yii:app()->User->Getid() Not Returning Value

Hi everyone,

 I've a problem, it might be a small one but I couldn't find the solution for this. Yii:app()->user->getId() or Yii:app()->user->id is not returning value. it just returning empty result. But I've set the id in my UserIdentity class. 

In my UserIdentity class I’ve this,




public function getId()

{

   return $this->id;

}



Please help me in this.

Thanks in advance.

Dhanendran Rajagopal.

Hi,

Have you added this code ?

		if($user->password!==$user->encrypt($this->password))


		{


			$this->errorCode=self::ERROR_PASSWORD_INVALID;


		}


		else


		{


			$this->_id = $user->id;


			// something goes here.....................


		}

Hi,

You’ll need to override the id property, present in your UserIdentity by default. To do it you can declare a new property called $_id, then your get method will return $_id, instead of $id. Look at this:




<?php 

 private $_id;

 public function getId(){

    return $this->_id;

}


?>



In your authenticate method you’ll assign your $_id property to your id caught of the database.




// When user is validated.

$this->_id=$record->id;



Got it ?

Regards.

did you do authentication before? maybe you logged as guest so it will returning NULL,

try to see what the value of


Yii::app()->user->isGuest.

I’m not sure, your code since not give an enough picture. :)