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

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

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

#1 User is offline   Dhanendran 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 05-April 13

Posted 15 August 2013 - 05:35 AM

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.
0

#2 User is offline   chandran 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 548
  • Joined: 08-October 12
  • Location:Austria

Posted 19 May 2014 - 02:56 AM

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.....................
}
Thanks
chandran nepolean

My own extension:
http://www.yiiframew...sion/ejqueryte/
http://www.yiiframew...uallistboxyii1/

My wiki
http://www.yiiframew...checkboxcolumn/

If it work dont hesitate to click +1 button
0

#3 User is offline   Diogo Alves 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 03-April 14

Posted 11 July 2014 - 02:22 PM

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.
"be different is normal"
0

#4 User is offline   Dan Din Dun 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 82
  • Joined: 09-February 10

Posted 17 March 2015 - 08:10 PM

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. :)
Thanks and Kind Regards
------
DanDinDun
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users