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.


Have you added this code ?







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

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



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:


 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.


Got it ?


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

try to see what the value of


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