So in my project I have a situation where I am storing data from multiple customer accounts in a single table. I need to somehow label this data with a site ID attribute so that users can only see stuff from their own site. My initial thought was to have a siteID foreign key in this transactions table and use that to limit result sets to just the stuff that user should see.
Should I (at login) set a session variable for siteID that can be accessed during operations?
<?php
class ZWebUser extends CWebUser
{
public $_model = null;
public function getModel()
{
if (!$this->_model)
{
$this->_model= User::model()->findByAttributes(array('username'=>$this->id));
}
return $this->_model;
}
}
This component can be accessed everywhere with Yii::app()->user. Extending it you can provide extra properties for access more that about the current user, in your case siteID or the siteData.
Take example from this implemetation: I used a singleton in order to aviod multiple queries for the same user record.