public function prepareSliderData()
 {
     $obj = new Slides();
     $slides = $obj->bySliderId($this->sliderId, $this->lang_id);
     // exit if slider not exist
     if (empty($slides)) {
         return null;
     }
     $this->slideDuration = $slides[0]['slider']['slide_duration'] ? $slides[0]['slider']['slide_duration'] : $this->slideDurationDefault;
     $this->slides = $slides;
 }
 /**
  * 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;
 }
Beispiel #3
0
    <?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']);
 /**
  * Finds the Slides model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Slides the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Slides::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }