/** * Controller的init方法会被自动首先调用 */ public function init() { //调试mysql if (isset($_GET['debug6429360'])) { $this->debug = true; DB_Mysqli::$DEBUG = 1; } $this->platform = isset($_REQUEST['platform']) ? $_REQUEST['platform'] : $this->platform; Yaf_Registry::set("platform", $this->platform); $this->isMobile = $this->platform == 'ios' || $this->platform == 'android'; $this->wap = !$this->isMobile && Common_Mobile::isMobile(); $this->uid = $this->get('uid', $this->post('uid', false)); $this->controllerName = $this->getRequest()->getControllerName(); $this->actionName = $this->getRequest()->getActionName(); $userModel = new UserModel(); /* if (!isset(Common_Config::$NotNeedLogin[$this->controllerName][$this->actionName]) && $this->isMobile && $this->needLogin && !$this->debug) { $token = $this->get("token", $this->post("token", false)); if (!$token) { $this->redirect(NULL, Common_Error::ERROR_TOKEN_NOT_EXISTS); } $api = $this->getRequestApi(); $check = Common_Token::check($token, $this->uid, strtolower($api)); if (!$check) { $this->redirect(NULL, Common_Error::ERROR_TOKEN); } }*/ $this->uid = $this->uid ? $this->uid : $userModel->getUid(); /** * 如果是Ajax请求, 则关闭HTML输出 */ if ($this->getRequest()->isXmlHttpRequest() || 'POST' == $this->getRequest()->getMethod()) { $this->ajax = true; Yaf_Dispatcher::getInstance()->disableView(); } else { //$path = $this->getView()->getScriptPath(); //$path[0] = $path[0] . "/" . strtolower($this->getRequest()->getControllerName()); //$this->getView()->setScriptPath($path[0]); } //print_r($this->uid?$this->uid:"null"); //验证登录 /*if ( !isset(Common_Config::$NotNeedLogin[$this->controllerName][$this->actionName]) && $this->needLogin && !$this->uid) { $this->redirect("/user/login?from=" . (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ""), Common_Error::ERROR_USER_NOT_LOGIN); $this->redirect("/user/verify", Common_Error::ERROR_USER_NOT_LOGIN); }*/ //用户信息 /* if($this->uid) { $user = $userModel->getUser($this->uid); $this->assign("uInfo", $user); Yaf_Registry::set("uid", $this->uid); }*/ }
/** * 获取一个数据库连接 数据库必须在conf/mysql.ini下有配置节信息 * * @param string $dbname 数据库名 * @return Ap_DB_Mysqli */ private function getDBConn($dbname) { $file = APP_PATH . '/conf/mysql.ini'; if (!file_exists($file)) { $file = APP_PATH . '/conf/mysql.ini'; } $ini = new Yaf_Config_Ini($file); $conf = $ini->get($dbname); $this->db = DB_Mysqli::getInstance($conf['host'], $conf['user'], $conf['pass'], $conf['db'], $conf['port']); }