Esempio n. 1
0
 public function save()
 {
     if (is_numeric($this->id)) {
         $query = TbQuery::findOne($this->id);
     } else {
         $query = new TbQuery();
     }
     $query->name = $this->name;
     $query->db_name = $this->db_name;
     $query->db_sql = $this->db_sql;
     if (!$query->save()) {
         echo json_encode(['code' => -1, 'msg' => json_encode($query->errors, JSON_UNESCAPED_UNICODE)]);
         return false;
     }
     echo json_encode(['code' => 0, 'msg' => '请求操作成功', 'result' => ['id' => $query->id]]);
     return true;
 }
Esempio n. 2
0
 public function actionDeleteItem()
 {
     $id = $_POST['id'];
     if (is_numeric($id)) {
         TbQuery::deleteAll('id = :id', [':id' => $id]);
     }
     echo json_encode(['code' => 0, 'msg' => '请求操作成功'], JSON_UNESCAPED_UNICODE);
 }
Esempio n. 3
0
 public function search()
 {
     $search = TbQuery::find();
     if ($this->name > '') {
         $search->andWhere("name like :name", [":name" => "%" . $this->name . "%"]);
     }
     $pages = new Pagination(['totalCount' => $search->count(), 'pageSize' => 10]);
     $datas = $search->offset($pages->offset)->limit($pages->limit)->all();
     return ['datas' => $datas, 'pages' => $pages];
 }