Yii Framework Forum: Yii user setstate / getstate - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii user setstate / getstate Rate Topic: -----

#1 User is offline   propelera 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 21-February 12

Posted 08 March 2012 - 05:45 AM

I am using Yii framework and I want to use user setstate, getstate methods but found out some problems, please can you help me to solve them? here is my codes:

UserIdentity.php

protected function afterLogin()
{
    Yii::app()->user->setState('username', $record->username);
    Yii::app()->user->setState('privilages', $record->privilages);
}


man layout
array('label'=>Yii::app()->user->getState('username'), 'url'=>array('/user/index'), 'visible'=>!Yii::app()->user->isGuest),


when user loges in it doesn't show his username, it just show whitespaces. so can you tell me what is wrong with it?
0

#2 User is offline   mbi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 616
  • Joined: 08-May 09

Posted 08 March 2012 - 05:55 AM

how to authenticate against database and setting the username, you can see here
http://blog.mbischof...uthentifizieren

however, $record is not available in your afterLogin-method
0

#3 User is offline   alexFidelis 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 17-November 11

Posted 08 March 2012 - 04:50 PM

View Postpropelera, on 08 March 2012 - 05:45 AM, said:

I am using Yii framework and I want to use user setstate, getstate methods but found out some problems, please can you help me to solve them? here is my codes:

UserIdentity.php

protected function afterLogin()
{
    Yii::app()->user->setState('username', $record->username);
    Yii::app()->user->setState('privilages', $record->privilages);
}


man layout
array('label'=>Yii::app()->user->getState('username'), 'url'=>array('/user/index'), 'visible'=>!Yii::app()->user->isGuest),


when user loges in it doesn't show his username, it just show whitespaces. so can you tell me what is wrong with it?


Try this:
man layout
array('label'=>Yii::app()->user->username, 'url'=>array('/user/index'), 'visible'=>!Yii::app()->user->isGuest),

Change from Yii::app()->user->getState('username') to Yii::app()->user->username
Remove what is in bold.
0

#4 User is offline   RicardoOrozco 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 04-June 14
  • Location:Cali, Colombia

Posted 23 July 2014 - 11:34 AM

View Postpropelera, on 08 March 2012 - 05:45 AM, said:


....

UserIdentity.php

protected function afterLogin()
{
    Yii::app()->user->setState('username', $record->username);
    Yii::app()->user->setState('privilages', $record->privilages);
}


.....



the function afterLogin know which is the variable $record? I dont see this in parameters. If this is global you need is $this->record
1

#5 User is offline   chiku 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 21-October 17

Posted 25 October 2017 - 06:32 AM

Hello,

Can anyone explain how we can use it? /How to use it, I do not understand, confused. :(

Thnx.
0

#6 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,824
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 25 October 2017 - 07:18 AM

View Postchiku, on 25 October 2017 - 06:32 AM, said:

Hello,

Can anyone explain how we can use it? /How to use it, I do not understand, confused. :(

Thnx.


http://www.yiiframew...pi/1.1/CWebUser

Note: this is an old Yii 1.1 discussion.
Don't forget to read The Definitive Guide to Yii (1.1 en) (1.1 sv) (2.0 en) | The class reference (1.1) (2.0) has the details
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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