Сделал через behavior класса CWebApplication.
class BWebApplication extends CBehavior
{
private $_site = null;
public function events()
{
return array('onBeginRequest' => '_onBeginRequest');
}
public function getSite()
{
return $this->_site;
}
public function loadSite($domain)
{
if (substr($domain, 0, 4) == 'www.')
$domain = str_replace('www.', '', $domain);
$this->_site = Site::model()->find('t.domain = :domain' , array(':domain' => $domain));
}
protected function _onBeginRequest()
{
$domain = (isset($_SERVER['HTTP_HOST']) === true) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
$this->loadSite($domain);
if ($this->_site === null)
throw new CHttpException(404, 'Site not found');
}
}
Или же есть другой вариант как лучше реализовать?