Ejemplo n.º 1
0
 protected function findModelBySlug($slug)
 {
     if (($model = Slider::findOne(['name' => $slug])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException();
     }
 }
Ejemplo n.º 2
0
 public function init()
 {
     parent::init();
     if (!$this->id) {
         $sliderId = \app\modules\slider\models\backend\Slider::findOne(['name' => $this->name]);
         $this->id = $sliderId->id;
     }
     Html::addCssClass($this->options, ['widget' => 'hidden widget-slider-' . $this->id]);
 }
Ejemplo n.º 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Slider::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => 3]]]);
     $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, 'name' => $this->name, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Ejemplo n.º 4
0
 protected function findSlider($id)
 {
     if (($model = Slider::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 5
0
 public function getSlider()
 {
     return $this->hasOne(Slider::className(), ['id' => 'slider_id']);
 }
Ejemplo n.º 6
0
use kartik\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use app\modules\slider\models\backend\Slider;
use app\widgets\grid\SetColumn;
/* @var $this yii\web\View */
/* @var $searchModel app\modules\slider\models\backend\search\SliderSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Слайдеры';
$this->params['breadcrumbs'][] = $this->title;
?>

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <p class="pull-left">
        <?php 
echo Html::a('<i class="material-icons">add</i> Добавить слайдер', ['create'], ['class' => 'btn btn-success']);
?>
    </p>

<?php 
Pjax::begin(['enablePushState' => false]);
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['attribute' => 'title'], ['attribute' => 'name'], ['class' => SetColumn::className(), 'filter' => Slider::getStatusesArray(), 'attribute' => 'status', 'name' => 'statusName', 'cssCLasses' => [Slider::STATUS_ACTIVE => 'success', Slider::STATUS_WAIT => 'warning'], 'contentOptions' => ['class' => 'status-column']], ['class' => 'app\\widgets\\grid\\ActionColumn', 'buttons' => ['view' => function ($url, $model, $key) {
    /** @var \app\modules\slider\models\backend\Slider $model */
    return Html::a('<i class="material-icons">visibility</i>', ['/slider/node/view', 'slug' => $model->name]);
}]]]]);
Pjax::end();