Best way to pass along a user's site ID?

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?

Or is there a better way?

You can extend the class WebUser like that:




<?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;

	}

}




And you can include it in config/main like that:




	'components'=>array(

		'user'=>array(

			// enable cookie-based authentication

			'class'=>'ZWebUser',

			'allowAutoLogin'=>true,

		),



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.