/** * 获取当前实例 * @return XF_Controller_Front */ public static function getInstance() { if (self::$_instance === null) { self::$_instance = new self(); } return self::$_instance; }
public function routeStartup(XF_Controller_Request_Abstract $request) { //导入重写规则 $router = XF_Controller_Front::getInstance()->getRouter(); require APPLICATION_PATH . '/rewrites/main/default.php'; require APPLICATION_PATH . '/rewrites/main/report.php'; }
/** * 添加相关资料到控制器中,方便Action中直接读取 */ protected function initAddDataToController() { //设置当前或之前访问的地区资料 $cookie = new XF_Cookie('local'); $province_id = $cookie->read(); $mod = new Application_Model_City(); $row = $mod->get($province_id); if ($row != false && $row->parent == '0') { $obj = (object) array('id' => $province_id, 'name' => $row->name, 'pinyin' => $row->pinyin); XF_Controller_Front::getInstance()->addHandleData('nowCity', $obj); XF_View::getInstance()->assign('nowCity', $obj); } //添加静态资源URL XF_Controller_Front::getInstance()->addHandleData('static_url', 'http://static.' . XF_Config::getInstance()->getDomain()); }
/** * 绑定当前域名到api模块 */ protected function initBindModule() { $this->_front->getRouter()->bindDomain('api', 'webapi.' . $this->_config->getDomain()); }
/** * 获取额外的操作数据 * @access public * @param string $name 数据名称 * @return mixed */ public function __get($name) { return XF_Controller_Front::getInstance()->getHandleData($name); }
/** * 添加相关资料到控制器中,方便Action中直接读取 */ protected function initAddDataToController() { if ($this->_nowCityDomain != NULL) { XF_Controller_Front::getInstance()->addHandleData('nowCity', $this->_nowCityDomain); XF_View::getInstance()->assign('nowCity', $this->_nowCityDomain); XF_DataPool::getInstance()->add('nowCity', $this->_nowCityDomain); } //添加静态资源URL XF_Controller_Front::getInstance()->addHandleData('static_url', 'http://static.' . XF_Config::getInstance()->getDomain()); }
/** * 获取模板起始位置目录 * @access public * @return string */ public function getTemplateStartLocation() { $this->_template_folder = XF_Controller_Front::getInstance()->getModuleDir() . '/views/' . XF_Config::getInstance()->getViewStyle(); return $this->_template_folder; }
/** * 运行启动器 * @access public * @return void */ public function run() { $st = microtime(true); $this->checkDomain(); $this->runStartup(); XF_DataPool::getInstance()->addList('Bootstrap_Inits', 'runStartup ' . sprintf('%.5fs', microtime(true) - $st)); if (!empty($_GET['xsessid'])) { $session_id = XF_Functions::authCode(urlencode($_GET['xsessid']), 'DECODE'); if ($session_id != '') { session_id($session_id); } } $stt = microtime(true); session_start(); XF_DataPool::getInstance()->addList('Bootstrap_Inits', 'session_start ' . sprintf('%.5fs', microtime(true) - $stt)); header("Content-type:text/html;charset=utf-8"); $this->_loadInit(); XF_DataPool::getInstance()->add('RunBootstrap', sprintf("%.6f", microtime(true) - $st)); XF_Controller_Front::getInstance()->init()->dispatch(); }