I am new to yii and am having trouble understanding something.
Im trying to access data from my user model class in another model class I have created.
I can access the user id by
$this->_userId = Yii::app()->user->id;.
However I want to get the username so I thought this would work.
$this->_username = Yii::app()->user->username;.
But it dosent and it comes up with Property "CWebUser.username" is not defined.
This works tho.
$this->_username = Yii::app()->user->name;
I don’t understand why it does as the veriable in my users class is $username and the coloum in my users table is obviously called username. i also cant access any of the other columns in the table or variables in my user class.
CWebUser only contains those attributes from your user table that you have passed to it in your application. Most applications use authentication in which the user id is passed to CWebUser, so that you can retrieve it with Yii::app()->user->id. At some point your application also has passed the username from your user table to the attribute name of CWebUser, apparently.
CWebUser is not a representation of your user table unless your application passes that information to it.