public function getCurrentSite($site_id = null) { // check session $session = new CHttpSession(); $session->open(); $sites = new Sites(); if ($session['site_id'] != $site_id) { $site_id = $session['site_id']; $data = $sites->findByPk($site_id); } else { $host_exp = explode(".", $_SERVER['HTTP_HOST']); if (count($host_exp) >= 3) { //sub domain (www., dev., etc) $host = $host_exp[1] . "." . $host_exp[2]; } else { $host = $_SERVER['HTTP_HOST']; } $data = $sites->find('domain = :domain', array(':domain' => $host)); } return $data; }