/** * 关注或取消关注 * Enter description here ... * @param unknown_type $followed_topicid */ public function actionToggleFollow($topicid) { $follow = TopicFollow::model()->findByAttributes(array('userId' => Yii::app()->user->id, 'topicid' => $topicid)); if (!$follow) { $follow = new TopicFollow(); $follow->userId = Yii::app()->user->id; $follow->topicid = $topicid; $follow->addTime = time(); if ($follow->save()) { echo true; Yii::app()->end(); } } else { $follow->delete(); echo false; } }
<?php /* @var $this TopicController */ /* @var $model Topic */ ?> <div class="row"> <div class="span8"> <div class="dxd-topic-header"> <div class="pull-left"><h2><?php echo $topic->name; ?> </h2></div> <div class="pull-right"> <?php echo CHtml::link(TopicFollow::model()->hasFollow(Yii::app()->user->id, $topic->id) ? '取消关注' : '<i class="icon-plus icon-white"></i>关注', array('topic/togglefollow', 'topicid' => $topic->id), array('onclick' => 'toggleFollow(this);return false;', 'class' => 'btn dxd-topic-followed' . " " . (TopicFollow::model()->hasFollow(Yii::app()->user->id, $topic->id) ? ' ' : ' btn-success '))); ?> </div> <div class="clearfix"></div> </div> <div class="dxd-topic-body"> <div class="tabbable"> <!-- Only required for left/right tabs --> <ul class="nav nav-pills"> <li <?php if ($type == 'course') { ?> class="active"<?php } ?> ><a href="#tab1" data-toggle="tab">课程</a></li> <li <?php