Thanks for your suggestion. I have extended the CWebUser class and now have the user data loading automatically. I am noticing that the query is executed on each page load. I would like to get the data into the session so the data is only pulled once per session. Suggestions?
You can simply cache the whole user model within your WebUser class. Then in your actual User AR clas, you delete the cache in afterSave/afterDelete methods. This way the cache should always represent fresh data. Of course you can also do it using session instead of cache.
@ frocco
Something like this:
class WebUser extends CWebUser
{
private $_model;
public function getModel()
{
if ($this->_model === null)
{
$this->_model = User::model()->findByPk($this->id);
}
return $this->_model;
}
}
// Now you can access the model with Yii::app()->user->model
Yes. I have the user record being placed into the session, but am noticing that the db is still hit for the data on every page request. I am trying to only hit the db for the user data if it is not in the session.