/** * 获取controller和action的名称 */ public static function getActionName() { if (php_sapi_name() === 'cli') { //cli模式 $options = getopt("c:a:"); $controllerName = $options['c']; if (!$controllerName) { $controllerName = DEFAULTCONTROLLER; } $actionName = $options['a']; if (!$actionName) { $actionName = DEFAULTACTION; } $controllerName = ucfirst($controllerName) . 'Command'; } else { session_start(); $controllerName = CommonRequest::getRequest('c'); if (!$controllerName) { $controllerName = DEFAULTCONTROLLER; } $actionName = CommonRequest::getRequest('a'); if (!$actionName) { $actionName = DEFAULTACTION; } $controllerName = ucfirst($controllerName) . 'Controller'; } return array($controllerName, $actionName); }
/** * 设置昵称 */ public function setNickName() { $this->outType = 'json'; $number = $_SESSION['number']; $name = CommonRequest::getRequest('name'); $mysql = CommonMysql::getInstance('localhost', 'root', ''); $data = $mysql->query('select nickName from test.user where nickName=:name', array('name' => $name)); if (!empty($data)) { $this->out = array('flag' => true, 'msg' => '该昵称已被占用!'); } else { $mysql->execute("insert into test.user(number,nickName) value ('{$number}','{$name}')"); $id = $mysql->getInsertID(); if (!empty($id)) { $_SESSION['nickName'] = $name; $this->out = array('flag' => true, 'msg' => '该昵称已被占用!'); } else { $this->out = array('flag' => false, 'msg' => '网络异常,请稍后重试!'); } } }