Exemple #1
0
 /**
  * 获取我关注的人
  * @param bool $onlyId
  * @return array|\yii\db\ActiveRecord[]
  */
 static function User($onlyId = true)
 {
     if ($onlyId) {
         if (!($FollowUser = Yii::$app->cache->get('FollowUserId' . Yii::$app->user->id))) {
             $FollowUser = ArrayHelper::map(Follow::find()->select('follow_id')->where(['user_id' => Yii::$app->user->id, 'type' => 1])->asArray()->all(), 'follow_id', 'follow_id');
             Yii::$app->cache->set('FollowUserId' . Yii::$app->user->id, $FollowUser, 0);
         }
     } else {
         if (!($FollowUser = Yii::$app->cache->get('FollowUser' . Yii::$app->user->id))) {
             $FollowUser = (new Query())->from(User::tableName())->where(['in', 'id', Follow::User()])->all();
             Yii::$app->cache->set('FollowUser' . Yii::$app->user->id, $FollowUser, 0);
         }
     }
     return $FollowUser;
 }
 public function actionFollow()
 {
     $this->title = '关注的人提的建议' . ' - ' . Yii::$app->name;
     $this->description = '';
     if (Yii::$app->user->isGuest) {
         return $this->redirect('/account/login?next=/account/follow');
     }
     $query = (new Query())->select('topic.*, node.enname, node.name, user.username, user.avatar')->from(Topic::tableName())->leftJoin(Node::tableName(), 'node.id = topic.node_id')->leftJoin(User::tableName(), 'user.id = topic.user_id')->where(['in', 'topic.user_id', Follow::User()]);
     $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['pageSize'], 'totalCount' => $query->count()]);
     $model = $query->orderBy(['id' => SORT_DESC])->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('follow', ['model' => $model, 'pagination' => $pagination]);
 }
Exemple #3
0
<?php

$follow = \common\models\Follow::User(false);
if (!empty($follow)) {
    ?>
<section>
    <div class="block-header"><small>我关注的人</small></div>
    <?php 
    foreach ($follow as $f) {
        ?>
        <article class="sidebar block-hot-topic">
            <table cellpadding="0" cellspacing="0" border="0" width="100%">
                <tbody><tr>
                    <td width="24" valign="middle" align="center">
                        <a href="/member/<?php 
        echo $f['username'];
        ?>
"><img src="<?php 
        echo Yii::$app->params['avatarUrl'] . '/24/' . $f['avatar'];
        ?>
" class="img-rounded"></a>
                    </td>
                    <td width="10"></td>
                    <td width="auto" valign="middle">
                <span class="hot_topic">
                <a href="/member/<?php 
        echo $f['username'];
        ?>
"><?php 
        echo $f['username'];
        ?>