public function actionFollow($isTrue) { if ($isTrue) { return ['status' => Tag::delFollow(Yii::$app->getRequest()->getBodyParams()['tag_id'])]; } else { return ['status' => Tag::addFollow(Yii::$app->getRequest()->getBodyParams()['tag_id'])]; } }
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();"); }
public function prepareDataProvider() { $followTagByUid = Tag::getFollowTagsByUid(\Yii::$app->user->id); if (!$followTagByUid) { return null; } $tags = ArrayHelper::getColumn($followTagByUid, 'name'); $query = \common\components\search\xunSearch\Feed::find(); $condition = ArrayHelper::merge(["or"], $tags); $query->where($condition); $condition = ['obj_type' => App::OBJ_TYPE_FEED]; $query->andwhere($condition); $query->with("author"); return new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 20]]); }
<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])]);
function actionIndex() { $roots = Tag::find()->roots()->all(); $hots = Tag::find()->limit(20)->orderBy("rand()")->all(); if (!Yii::$app->user->isGuest) { $my = Tag::getFollowTagsByUid(Yii::$app->user->id, false); } else { $my = null; } return $this->render("index", ['roots' => $roots, 'hots' => $hots, 'my' => $my]); }