<?php public function actionIndex() { $searchModel = new ArticleSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); } ?>
视图:
<?php $form = ActiveForm::begin([ 'action' => ['index'], 'method' => 'get', 'id' => 'cateadd-form', 'options' => ['class' => 'form-horizontal'], ]); ?> <?= $form->field($searchModel, 'title',[ 'options'=>['class'=>''], 'inputOptions' => ['placeholder' => '文章搜索','class' => 'input-sm form-control'], ])->label(false) ?> <?= Html::submitButton('Go!', ['class' => 'btn btn-sm btn-primary']) ?> <?php ActiveForm::end(); ?> <?= GridView::widget([ 'dataProvider' => $dataProvider, 'layout'=> '{items}<div>{pager}</div>', 'pager'=>[ //'options'=>['class'=>'hidden']//关闭自带分页 'firstPageLabel'=>"First", 'prevPageLabel'=>'Prev', 'nextPageLabel'=>'Next', 'lastPageLabel'=>'Last', ], //这部分和上面的分页是一样的