示例#1
0
 public function action_index()
 {
     TXEvent::on(onSql);
     $ids = array_keys($this->projectDAO->rightJoin($this->testDAO, ['type' => 'type'])->filter([['name' => 'test'], ['>=' => ['time' => time()]]])->query([['id' => 'projectId']], 'projectId'));
     $this->userDAO->filter(['projectId' => [2, 3, 4]])->query();
     $this->userDAO->leftJoin($this->projectDAO, ['projectId' => 'id'])->rightJoin($this->testDAO, [[], ['type' => 'type']])->filter([[], ['name' => 'test'], ['>=' => ['time' => time()]]])->query(['*']);
     $result = $this->userDAO->filter(['>=' => ['id' => 20], 'count' => 2])->limit(2)->query();
     TXLogger::info($result);
     $data = $this->getParam('test');
     $params = array('test' => $data);
     //        TXDatabase::start();
     //        $this->testDAO->add(['name'=>'rollback', 'userId'=>10, 'time'=>time(), 'type'=>2]);
     //        $this->userDAO->add(['name'=>'rollback']);
     //        TXDatabase::commit();
     return $this->display('main/test', $params);
 }
示例#2
0
 /**
  * 执行请求
  * @param TXRequest $request
  * @throws TXException
  * @return mixed
  */
 private function call(TXRequest $request)
 {
     $module = $request->getModule() . 'Action';
     $method = $request->getMethod();
     $args = $this->getArgs($module, $method);
     $object = $this->getAction($module, $request);
     if ($object instanceof TXResponse || $object instanceof TXJSONResponse) {
         TXEvent::trigger(afterAction, array($request));
         return $object;
     }
     if ($object instanceof TXAction) {
         $result = call_user_func_array([$object, $method], $args);
         TXEvent::trigger(afterAction, array($request));
         return $result;
     } else {
         throw new TXException(2001, $request->getModule(), 404);
     }
 }
示例#3
0
 /**
  * 构造函数
  * @param string $code
  * @param array $params
  * @param string $html
  */
 public function __construct($code, $params = array(), $html = "500")
 {
     $message = $this->fmt_code($code, $params);
     //        \Biny\Logger::error($message, array('file'=>$this->getFile().":".$this->getLine(), 'trace'=>$this->getTraceAsString()));
     if (class_exists('TXEvent')) {
         TXEvent::trigger(onException, array($code, array($message, $this->getTraceAsString())));
     }
     if (class_exists('TXDatabase')) {
         TXDatabase::rollback();
     }
     try {
         if (RUN_SHELL) {
             echo "<b>Fatal error</b>:  {$message} in <b>{$this->getFile()}</b>:<b>{$this->getLine()}</b>\nStack trace:\n{$this->getTraceAsString()}";
             exit;
         }
         if ($httpCode = TXConfig::getConfig($html, 'http')) {
             header($httpCode);
         }
         if (SYS_DEBUG) {
             echo "<pre>";
             echo "<b>Fatal error</b>:  {$message} in <b>{$this->getFile()}</b>:<b>{$this->getLine()}</b>\nStack trace:\n{$this->getTraceAsString()}";
         } else {
             if (TXApp::$base->request->isShowTpl() || !TXApp::$base->request->isAjax()) {
                 $params = ['CDN_ROOT' => TXConfig::getAppConfig('CDN_ROOT')];
                 echo new TXResponse("error/exception", array('msg' => $this->messages[$html] ?: "系统数据异常:{$html}"), $params);
             } else {
                 $data = array("flag" => false, "error" => $this->messages[$html] ?: "系统数据异常:{$html}");
                 echo new TXJSONResponse($data);
             }
         }
         die;
     } catch (TXException $ex) {
         //防止异常的死循环
         echo "system Error";
         exit;
     }
 }
示例#4
0
 /**
  * 更新数据或者加1
  * @param $inserts
  * @param $sets ['num'=>2]
  * @return bool|int|mysqli_result|string
  */
 public function createOrAdd($inserts, $sets)
 {
     $set = $this->buildCount($sets);
     $fields = $this->buildInsert($inserts);
     $sql = sprintf("INSERT INTO %s %s ON DUPLICATE KEY UPDATE %s", $this->dbTable, $fields, $set);
     TXEvent::trigger(onSql, [$sql]);
     return $this->execute($sql, true);
 }
示例#5
0
 /**
  * @param string $msg
  * @param bool $encode
  * @return TXJSONResponse|TXResponse
  */
 public function error($msg = "数据异常", $encode = true)
 {
     TXEvent::trigger(onError, array($msg));
     if ($this->showTpl && (TXApp::$base->request->isShowTpl() || !TXApp::$base->request->isAjax())) {
         return $this->display('error/msg', ['msg' => $msg]);
     } else {
         $data = array("flag" => false, "error" => $msg);
         return $this->json($data, $encode);
     }
 }
示例#6
0
文件: TXApp.php 项目: billge1205/biny
 /**
  * 核心初始化
  */
 private static function init()
 {
     TXAutoload::init();
     set_error_handler(['TXApp', 'handleError']);
     TXEvent::init();
     self::$controller = TXFactory::create('TXController');
 }
示例#7
0
 /**
  * 启动类
  */
 public static function init()
 {
     TXEvent::on(onException, ['TXEvent', 'onException']);
     TXEvent::on(onRequest, ['TXEvent', 'onRequest']);
 }
示例#8
0
文件: TXDAO.php 项目: billge1205/biny
 /**
  * 查询条件
  * @param $method ['max', 'min', 'sum', 'avg']
  * @param $args
  * @return mixed
  * @throws TXException
  */
 public function __call($method, $args)
 {
     if (in_array($method, $this->methods)) {
         if ($this instanceof TXSingleDAO) {
             $cond = new TXSingleCond($this);
         } else {
             $cond = new TXDoubleCond($this);
         }
         return call_user_func_array([$cond, $method], $args);
     } else {
         if (in_array($method, $this->calcs)) {
             $where = isset($args[1]) && $args[1]->get('where') ? " WHERE " . $args[1]->get('where') : "";
             $sql = sprintf("SELECT %s(`%s`) as `%s` FROM %s%s", $method, $args[0], $method, $this->getTable(), $where);
             TXEvent::trigger(onSql, [$sql]);
             $ret = $this->sql($sql, null, self::FETCH_TYPE_ONE);
             return $ret[$method] ?: 0;
         } else {
             throw new TXException(3009, array($method, get_called_class()));
         }
     }
 }