Exemplo n.º 1
0
 public function actionHome()
 {
     $query = Basketball::find();
     $pagination = new Pagination(['defaultPageSize' => 1, 'totalCount' => $query->count()]);
     $news = $query->orderBy('Title')->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('home', ['pagination' => $pagination, 'news' => $news]);
 }
Exemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Basketball::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]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'post', $this->post]);
     return $dataProvider;
 }
Exemplo n.º 3
0
 public function actionIndex()
 {
     $model = new Basketball();
     //分页
     $curPage = Yii::$app->request->get('page', 1);
     $pageSize = 3;
     //搜索
     $id = Yii::$app->request->get('id', '');
     $title = Yii::$app->request->get('title', '');
     $search = $id && $title ? ['like', $id, ['>=', 6]] : '';
     //查询语句
     $query = $model->find()->orderBy('title');
     $data = $model->getPages($query, $curPage, $pageSize, $search);
     $pages = new Pagination(['totalCount' => $data['count'], 'pageSize' => $pageSize]);
     return $this->render('index', ['pages' => $pages, 'data' => $data, 'model' => $model]);
 }