/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Upload::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(['upload_id' => $this->upload_id, 'scholar_scholar_id' => $this->scholar_scholar_id, 'scholar_school_school_id' => $this->scholar_school_school_id]); $query->andFilterWhere(['like', 'upload_form', $this->upload_form])->andFilterWhere(['like', 'upload_file_name', $this->upload_file_name]); return $dataProvider; }
<?php use yii\grid\GridView; use yii\data\ActiveDataProvider; use common\models\Upload; /* @var $this yii\web\View */ $this->title = 'Uploads'; $this->params['breadcrumbs'][] = $this->title; $dataProvider = new ActiveDataProvider(['query' => Upload::find(), 'pagination' => ['pageSize' => 20]]); ?> <div class="box"> <div class="box-body"> <?php if (Yii::$app->user->can('listResources')) { echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'filename', 'filesize', 'mimetype', ['attribute' => 'created_by'], ['attribute' => 'created_at', 'format' => ['datetime', 'php:Y-m-d H:i:s']], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}']]]); } ?> </div> </div>