/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Slides::find(); // add conditions that should always apply here $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; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'slider_id' => $this->slider_id, 'priority' => $this->priority]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'image', $this->image]); return $dataProvider; }
<?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'slide_duration')->textInput(['maxlength' => true]); ?> <hr> <div class="form-group row"> <div class="col-lg-2"><?php echo Yii::t('main', 'Slides'); ?> </div> <div class="col-lg-10"> <?php $slidesDataProvider = new ActiveDataProvider(['query' => Slides::find()->where(['=', 'slider_id', $model->id])]); echo GridView::widget(['dataProvider' => $slidesDataProvider, 'columns' => [['class' => 'yii\\grid\\ActionColumn', 'urlCreator' => function ($action, $model) { return Url::toRoute(['slides/' . $action, 'id' => $model->id]); }, 'template' => '{update} <br> {delete} ', 'contentOptions' => ['class' => 'text-left', 'nowrap' => 'nowrap']], ['contentOptions' => ['class' => 'col-sm-4 text-center'], 'attribute' => 'Image', 'format' => 'html', 'value' => function ($model) { return Html::img($model->image, ['class' => 'image_preview']); }], ['contentOptions' => ['class' => 'col-sm-8 text-center'], 'attribute' => 'Info', 'format' => 'html', 'value' => function ($model) { return $model->title; }]]]); ?> </div> </div> <hr> <?php echo Html::a('new slide', Url::toRoute(['slides/create', 'slider_id' => $model->id]), ['class' => 'btn btn-success']);