/** * @inheritdoc */ public function init() { parent::init(); if ($this->alias === null) { throw new InvalidConfigException('Property "alias" must be set.'); } $this->model = models\Slider::findByAlias($this->alias); if (!$this->model->active) { $this->model = null; } if (empty($this->items)) { $this->prepareItems(); } $this->registerClientScript(); }
/** * Initializes the widget. */ public function init() { parent::init(); if (ctype_digit($this->album)) { $condition = $this->album; } elseif (is_string($this->album)) { $condition = ['slug' => $this->album]; } else { throw new \yii\base\InvalidParamException('Invalid album parameter passed to a method.'); } $album = Album::findOne($condition); if (!$album) { throw new \yii\web\NotFoundHttpException('Album was not found.'); } $media = $album->getMedia()->all(); foreach ($media as $image) { $this->items[] = ['content' => $this->render($this->contentView, ['image' => $image]), 'caption' => $this->render($this->captionView, ['image' => $image]), 'options' => $this->itemsOptions]; } }
public function init() { parent::init(); Html::addCssClass($this->options, 'slide'); }
/** * @throws InvalidConfigException */ public function init() { if (!$this->key) { throw new InvalidConfigException(); } $cacheKey = [WidgetCarousel::className(), $this->key]; $items = \Yii::$app->cache->get($cacheKey); if ($items === false) { $items = []; $query = WidgetCarouselItem::find()->joinWith('carousel')->where(['{{%widget_carousel_item}}.status' => 1, '{{%widget_carousel}}.status' => WidgetCarousel::STATUS_ACTIVE, '{{%widget_carousel}}.key' => $this->key])->orderBy(['order' => SORT_ASC]); foreach ($query->all() as $k => $item) { /** @var $item \common\models\WidgetCarouselItem */ if ($item->path) { $items[$k]['content'] = Html::img($item->getImageUrl()); } if ($item->url) { $items[$k]['content'] = Html::a($items[$k]['content'], $item->url, ['target' => '_blank']); } if ($item->caption) { $items[$k]['caption'] = $item->caption; } } \Yii::$app->cache->set($cacheKey, $items, 60 * 60 * 24 * 365); } $this->items = $items; parent::init(); }