Hello,
what is the recommended way to add more info to CWebuser.
1. Extend the CWebuser class ? and using the methods/getters-setters assign values like firsname/lastname.
OR
2. make entries like this inside the authenticate() method of UserIdentity ?
$this->setState('FirstName', $users->FIRSTNAME);
$this->setState('LastName', $users->LASTNAME);
thanks
Arvind
Page 1 of 1
Add more info to CWebUser Deals about the recommended way to add info th CWebUser
#3
Posted 08 February 2010 - 11:20 PM
Arvind, on 08 February 2010 - 07:08 PM, said:
Hello,
what is the recommended way to add more info to CWebuser.
1. Extend the CWebuser class ? and using the methods/getters-setters assign values like firsname/lastname.
OR
2. make entries like this inside the authenticate() method of UserIdentity ?
$this->setState('FirstName', $users->FIRSTNAME);
$this->setState('LastName', $users->LASTNAME);
thanks
Arvind
what is the recommended way to add more info to CWebuser.
1. Extend the CWebuser class ? and using the methods/getters-setters assign values like firsname/lastname.
OR
2. make entries like this inside the authenticate() method of UserIdentity ?
$this->setState('FirstName', $users->FIRSTNAME);
$this->setState('LastName', $users->LASTNAME);
thanks
Arvind
I recommend you load the user model in your "WebUser" class like
class WebUser extends CWebUser {
public function getModel()
{
$user = User::model()->findByPk($this->getId());// providing the value returned from getId() is the PK in your user table/model
return $user;
}
}
you can then access the model like $user = Yii::app()->user->getModel(); for the current user.
if($user!==null)
{
// can access all public user AR methods and attributes eg: $user->firstname, $user->status... etc
}
php:
foreach(array('cat', 'dog', 'cow') as $animal) echo $animal."\n";
python:
[(animal, print(animal)) for animal in ['cat', 'dog', 'cow']]
ruby:
['cat', 'dog', 'cow'].each {|animal| puts animal}
You say Tomato, I say Tomato.
#4
Posted 09 February 2010 - 03:35 AM
Hello,
I might sound very dumb, but how come this works ?
I extend the CWebUser class like this
class WebUser extends CWebUser
{
public function Foo();
}
then how come Foo() is available to Yii::app()->user.
Is not Yii::app()->user of type CWebUser ?
We have extended CWebUser, so Foo() should be available to WebUser. So how come its available to Yii::app()->user ?
I might sound very dumb, but how come this works ?
I extend the CWebUser class like this
class WebUser extends CWebUser
{
public function Foo();
}
then how come Foo() is available to Yii::app()->user.
Is not Yii::app()->user of type CWebUser ?
We have extended CWebUser, so Foo() should be available to WebUser. So how come its available to Yii::app()->user ?
#5
Posted 09 February 2010 - 04:25 AM
Arvind, on 09 February 2010 - 03:35 AM, said:
Hello,
I might sound very dumb, but how come this works ?
I extend the CWebUser class like this
class WebUser extends CWebUser
{
public function Foo();
}
then how come Foo() is available to Yii::app()->user.
Is not Yii::app()->user of type CWebUser ?
We have extended CWebUser, so Foo() should be available to WebUser. So how come its available to Yii::app()->user ?
I might sound very dumb, but how come this works ?
I extend the CWebUser class like this
class WebUser extends CWebUser
{
public function Foo();
}
then how come Foo() is available to Yii::app()->user.
Is not Yii::app()->user of type CWebUser ?
We have extended CWebUser, so Foo() should be available to WebUser. So how come its available to Yii::app()->user ?
didn't you specify the class for the user component in your config to be 'WebUser'? if you did, then Yii::app()->user will reyurn an instance of WebUser.
php:
foreach(array('cat', 'dog', 'cow') as $animal) echo $animal."\n";
python:
[(animal, print(animal)) for animal in ['cat', 'dog', 'cow']]
ruby:
['cat', 'dog', 'cow'].each {|animal| puts animal}
You say Tomato, I say Tomato.
#6
Posted 09 February 2010 - 04:44 AM
aaah yes, now its all clear!!!
how did i miss that one ?
thanks a ton
Arvind
how did i miss that one ?
thanks a ton
Arvind
#7
Posted 09 February 2010 - 07:39 AM
KISS - Keep It Simple Stupid
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
http://hmsegura.blogspot.com/
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
http://hmsegura.blogspot.com/
Share this topic:
Page 1 of 1

Help












