Commit fc1e1613ff151375de2ebdfd0d98194f42dc1bb6
1 parent
453db918
-Slider sorting
Showing
1 changed file
with
40 additions
and
30 deletions
Show diff stats
frontend/widgets/Slider.php
| 1 | <?php | 1 | <?php |
| 2 | -namespace frontend\widgets; | ||
| 3 | - | ||
| 4 | -use yii\base\Widget; | ||
| 5 | - | ||
| 6 | -class Slider extends Widget | ||
| 7 | -{ | ||
| 8 | - public $title; | ||
| 9 | - | ||
| 10 | - public function init(){ | ||
| 11 | - | ||
| 12 | - parent::init(); | ||
| 13 | - | ||
| 14 | - } | ||
| 15 | - | ||
| 16 | - | ||
| 17 | - public function run() | 2 | + namespace frontend\widgets; |
| 3 | + | ||
| 4 | + use yii\base\Widget; | ||
| 5 | + | ||
| 6 | + class Slider extends Widget | ||
| 18 | { | 7 | { |
| 19 | - | ||
| 20 | - | ||
| 21 | - $slider = \common\models\Slider::find()->where([\common\models\Slider::tableName().'.title'=>$this->title])->joinWith("sliderImage")->one(); | ||
| 22 | - if($slider instanceof \common\models\Slider){ | ||
| 23 | - return $this->render('slider',[ | ||
| 24 | - 'slider'=>$slider, | ||
| 25 | - 'title'=>$this->title | ||
| 26 | - ]); | ||
| 27 | - | 8 | + public $title; |
| 9 | + | ||
| 10 | + public function init() | ||
| 11 | + { | ||
| 12 | + | ||
| 13 | + parent::init(); | ||
| 14 | + | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + public function run() | ||
| 18 | + { | ||
| 19 | + | ||
| 20 | + $slider = \common\models\Slider::find() | ||
| 21 | + ->where([ \common\models\Slider::tableName() . '.title' => $this->title ]) | ||
| 22 | + ->joinWith( | ||
| 23 | + [ | ||
| 24 | + "sliderImage" => function ($query) { | ||
| 25 | + $query->orderBy('sort'); | ||
| 26 | + }, | ||
| 27 | + ] | ||
| 28 | + ) | ||
| 29 | + ->one(); | ||
| 30 | + if ($slider instanceof \common\models\Slider) { | ||
| 31 | + return $this->render( | ||
| 32 | + 'slider', | ||
| 33 | + [ | ||
| 34 | + 'slider' => $slider, | ||
| 35 | + 'title' => $this->title, | ||
| 36 | + ] | ||
| 37 | + ); | ||
| 38 | + | ||
| 28 | } | 39 | } |
| 29 | - | ||
| 30 | - | ||
| 31 | - } | ||
| 32 | - | ||
| 33 | -} | ||
| 34 | \ No newline at end of file | 40 | \ No newline at end of file |
| 41 | + | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + } | ||
| 35 | \ No newline at end of file | 45 | \ No newline at end of file |