Esempio n. 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Diary::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'c_time' => $this->c_time, 'u_time' => $this->u_time]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'tag', $this->tag])->andFilterWhere(['like', 'type', $this->type])->andFilterWhere(['like', 'jurisdiction', $this->jurisdiction]);
     return $dataProvider;
 }
Esempio n. 2
0
 /**
  * Lists all Diary models.
  * @return mixed
  */
 public function actionIndex()
 {
     $query = \common\models\Diary::find();
     $query->where(' `status` != :status', [':status' => \common\base\Status::DELETE]);
     $request = Yii::$app->getRequest()->get();
     unset($request['r']);
     $total = $query->count();
     $pageSize = 10;
     $pager = new \common\base\Page();
     $pager->pageName = 'page';
     $pageBarNum = 5;
     $pages = $pager->show($total, $pageSize, $pageBarNum);
     $page = isset($request['page']) ? $request['page'] : 1;
     $offset = $pageSize * ($page - 1);
     if ($offset >= $total) {
         $offset = $total;
     }
     $query->orderBy(' `id` DESC');
     $query->offset($offset);
     $query->limit($pageSize);
     $list = $query->asArray()->all();
     return $this->render('index', ['pages' => $pages, 'total' => $total, 'list' => $list]);
 }