public function init() { parent::init(); $this->isFollow = Tag::isFollow($this->tagId); if ($this->isFollow) { $this->label = "已关注"; } $this->getView()->registerJsFile('/js/jquery.toggle.js', ['depends' => [JqueryAsset::className()]]); $this->getView()->registerJs("\$('.tagFollowToggle').toggle();"); }
<div class="mb10"> <dl class="menu"> <dt>相关</dt> <?php $parent = $model->parents()->all(); $children = $model->children(1)->all(); $tags = ArrayHelper::merge($parent, $children); if (!empty($tags)) { foreach ($tags as $tag) { echo '<dd>' . Html::a($tag->name, $tag->url) . '</dd>'; } } ?> <dd> </dd> <dd> </dd> </dl> </div> </div> </div> <?php $isFollow = Tag::isFollow($model->id, Yii::$app->user->id); $js = "var isFollow = " . ($isFollow ? 1 : 0) . "; var tagId=" . $model->id . ";"; $this->registerJs($js, 1); $this->registerJsFile('/js/angular.min.js'); $this->registerJsFile('/js/angular.tag.js'); echo FavModal::widget(['collections' => Collection::findAll(['author_id' => Yii::$app->user->id])]);