public function loadModel($id) { if (!($model = Tag::findOne($id))) { throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested tag does not exist.')); } return $model; }
protected function launch() { if (!$this->tag instanceof Tag) { $this->tag = Tag::findOne(intval($this->tag)); } if (empty($this->tag)) { throw new InvalidConfigException(Yii::t('gromver.platform', 'Tag must be set.')); } echo $this->render($this->layout, ['dataProvider' => new ActiveDataProvider(['query' => $this->getQuery(), 'pagination' => ['pageSize' => $this->pageSize], 'sort' => ['defaultOrder' => [$this->sort => (int) $this->dir]]]), 'itemLayout' => $this->itemLayout, 'model' => $this->tag]); }
protected function launch() { if (!$this->tag instanceof Tag) { $this->tag = Tag::findOne(intval($this->tag)); } if (empty($this->tag)) { throw new InvalidConfigException(Yii::t('gromver.platform', 'Tag not found.')); } echo $this->render($this->layout, ['dataProvider' => new ActiveDataProvider(['query' => $this->tag->getTagToItems(), 'pagination' => ['pageSize' => $this->pageSize]]), 'itemLayout' => $this->itemLayout, 'model' => $this->tag]); $this->tag->hit(); }
/** * @param $event \Yii\base\Event */ public function afterSave($event) { $this->owner->getDb()->transaction(function ($db) use($event) { if (isset($this->_tags) && is_array($this->_tags)) { $oldTags = ArrayHelper::map($this->owner->tags, 'id', 'id'); $this->owner->setIsNewRecord(false); $toAppend = array_diff($this->_tags, $oldTags); $toRemove = array_diff($oldTags, $this->_tags); foreach ($toAppend as $id) { $tag = Tag::findOne($id); $this->owner->link('tags', $tag, ['item_class' => $this->owner->className()]); } if ($event->name == BaseActiveRecord::EVENT_AFTER_UPDATE) { foreach ($toRemove as $id) { $tag = Tag::findOne($id); $this->owner->unlink('tags', $tag, true); } } } }); }
/** * Finds the Tag model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Tag the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Tag::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested page does not exist.')); } }