I want to check if what I was doing was right so I have this code...
$user= Yii::app()->user->id;
$account= $user->account_type;
print_r($account);
My table has the following attributes: account_id, username, password and account_type
but when I do the code... I get the following error:
"Trying to get property of non object"
please help, I am a beginner so I'm sorry for a basic problem...
You can create a model for your table using gii, and then query the model using the user id, something like:
$user= Yii::app()->user->id;
$userModel = User::model()->findByPK($user);
$account= $userModel->account_type;
or, you can setState in your UserIdentity.php after validating username and password, like:
$this->setState('accounttype', $userModel->account_type);
and use this wherever you want just like:
echo Yii::app()->user->accounttype
You can check this yii wiki
Hope that helps :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With