Ejemplo n.º 1
0
 /**
  * 测试首个请求
  */
 public function indexAction()
 {
     $row = \BalanceDb::instance('db')->fetchOne('select now() as mysqlNow');
     echo $row ? "mysqNow is {$row['mysqlNow']}" : "sql is error";
     echo "\n";
     echo 'jingwu tester';
 }
Ejemplo n.º 2
0
 /**
  * 设置配置文件
  * @param unknown $configs
  */
 public static function config($configs = array())
 {
     self::$configs = $configs;
     if (isset(self::$configs['default'])) {
         self::$dbKeyDefault = self::$configs['default'];
     }
     return true;
 }
Ejemplo n.º 3
0
     $dbWriteConfig = $currentConfig['write']['db'];
     $di->set($keyWrite, function () use($dbWriteConfig) {
         return new Phalcon\Db\Adapter\Pdo\Mysql($dbWriteConfig);
     });
     $dbReadConfig = current($currentConfig['reads']);
     $di->set($keyRead, function () use($dbReadConfig) {
         return new Phalcon\Db\Adapter\Pdo\Mysql($dbReadConfig);
     });
 }
 //设置默认数据库连接
 $defaultDbKey = 'db' . ucfirst($config->balanceDb->default);
 $di->set('db', $di->get($defaultDbKey));
 $defaultDbKey = 'db' . ucfirst($config->balanceDb->default);
 $di->set('db_read', $di->get($defaultDbKey . '_read'));
 //加载DB负载均衡
 BalanceDb::config($config->balanceDb->toArray());
 //Redis负载均衡
 BalanceRedis::config($config->balanceRedis->toArray());
 //URL 工具类
 TUrl::config($config->url->toArray());
 //config 工具类
 TConfig::instance()->setAll($config->toArray());
 //实例化应用
 $application = new \Phalcon\Mvc\Application($di);
 //注册模块
 $modules = array();
 foreach ($config->modules as $key => $params) {
     if ($key == 'default') {
         continue;
     }
     $modules[$key] = array('className' => sprintf('Module\\%s\\Module', ucfirst($key)), 'path' => $params['path']);
Ejemplo n.º 4
0
 public function editAjaxAction()
 {
     \BUser::instance()->checkLogin();
     if ($this->request->isAjax()) {
         $headimg = $this->request->getPost('headimg', 'string') ? $this->request->getPost('headimg', 'string') : '';
         $sex = $this->request->getPost('sex', 'string') ? $this->request->getPost('sex', 'string') : '';
         $qq = $this->request->getPost('qq', 'string') ? $this->request->getPost('qq', 'string') : '';
         $email = $this->request->getPost('email', 'string') ? $this->request->getPost('email', 'string') : '';
         $nickname = $this->request->getPost('nickname', 'string') ? $this->request->getPost('nickname', 'string') : '';
     }
     $uid = $this->session->get('uid');
     $userInfo = \User::findFirst("id = {$uid}");
     //imgbase64转URL
     if (preg_match('/^(data:\\s*image\\/(\\w+);base64,)/', $headimg, $result)) {
         $type = $result[2];
         $new_file = __DIR__ . '/../../public/upload/head/haed_' . $uid . '.' . $type;
         if (!file_exists($new_file)) {
             //如果文件不存在(默认为当前目录下)
             $fh = fopen($new_file, "w");
             fclose($fh);
             //关闭文件
         }
         if (file_put_contents($new_file, base64_decode(str_replace($result[1], '', $headimg)))) {
             $new_file = '/upload/head/haed_' . $uid . '.' . $type;
         } else {
             $new_file = '';
         }
     } else {
         $new_file = '';
     }
     $sql = 'UPDATE `ys_user` SET ';
     if ($userInfo) {
         if ($new_file) {
             $sql .= "headimg = '" . $new_file . "',";
         }
         if ($sex) {
             $sql .= "sex = '" . $sex . "',";
         }
         if ($qq) {
             if (!is_numeric($qq)) {
                 \ToolFlash::error("请输入正确的QQ号码");
             }
             if (\User::findFirst("id != {$uid} AND qq={$qq}")) {
                 \ToolFlash::error("QQ号码已存在");
             }
             $sql .= "qq = '" . $qq . "',";
         }
         if ($email) {
             if (!\ToolCheck::is_email($email)) {
                 \ToolFlash::error("邮箱格式不正确");
             }
             if (\User::findFirst("id != {$uid} AND email='{$email}'")) {
                 \ToolFlash::error("邮箱已存在");
             }
             $sql .= "email = '" . $email . "',";
         }
         if ($nickname) {
             $sql .= "nickname = '" . $nickname . "',";
         }
         $sql .= "utime = '" . time() . "' WHERE id = {$uid}";
         $db = \BalanceDb::instance();
         if ($db->execute($sql)) {
             $userInfo = \User::findFirst("id = {$uid}");
             \BUser::instance()->setLoginSession($userInfo->toArray());
             \ToolFlash::success("修改成功");
         } else {
             foreach ($userInfo->getMessages() as $message) {
                 error_log(print_r($message, true));
             }
             \ToolFlash::error("修改失败");
         }
     } else {
         \ToolFlash::error("找不到用户信息");
     }
 }