Esempio n. 1
0
 /**
  * 搜索.
  * 
  * @access public
  * @return void
  */
 public function searchAction()
 {
     $type = (int) I('post.type', 0);
     // 搜索类型: 0分类, 1社区资讯.
     $catId = I('post.catId', NULL);
     // 搜索的栏目 ID, 为 NULL, 根据类型全站搜索.
     $keyword = I('post.keyword', '');
     // 关键字为空, 返回空.
     $pageConfig = C('page');
     // 分页参数变量名配置项.
     $page = (int) I('post.' . $pageConfig['var_page'], 1);
     // page.
     $pageSize = (int) I('post.' . $pageConfig['var_page_size'], 10);
     // rows.
     $allowType = [0, 1];
     $catId = empty($catId) || !is_numeric($catId) ? NULL : (int) $catId;
     unset($pageConfig);
     if (!isset($allowType[$type])) {
         $this->setAjaxData(Message::PARAM_ERROR, Message::get(Message::PARAM_ERROR))->myAjaxReturn();
     }
     $model = NULL;
     switch ($type) {
         case 0:
             $model = new CtgDataModel();
             break;
         default:
             $model = new SqDataModel();
     }
     $result = ['totalRows' => 0, 'lists' => []];
     if (!empty($keyword)) {
         $result = $model->search($keyword, $catId, $page, $pageSize);
     }
     $this->setAjaxData(Message::SUCCESS, Message::get(Message::SUCCESS), $result)->myAjaxReturn();
 }