本文整理汇总了PHP中app\modules\user\models\User::getIsFollow方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getIsFollow方法的具体用法?PHP User::getIsFollow怎么用?PHP User::getIsFollow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\modules\user\models\User
的用法示例。
在下文中一共展示了User::getIsFollow方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionIndex
/**
* Displays a single User model.
* @param integer $id
* @return mixed
*/
public function actionIndex($id)
{
$model = $this->findModel($id);
if (Yii::$app->Request->isAjax) {
$avatar = Yii::getAlias('@avatar') . $model->avatar;
$username = $model->username;
$userUrl = Url::toRoute(['/user/view', 'id' => $username]);
$userData = Yii::$app->userData->getKey(true, null, $model->id);
$followUrl = Url::toRoute(['/user/user/follow', 'id' => $model->id]);
//关注的文字
if (User::getIsFollow($model->id)) {
$followBtn = '<span class="glyphicon glyphicon glyphicon-eye-close"></span> ' . Yii::t('app', 'Unfollow');
} else {
$followBtn = '<span class="glyphicon glyphicon-plus"></span> ' . Yii::t('app', 'Follow');
}
$html = <<<HTML
<div class="media">
<div class="media-left">
<a href="{$userUrl}">
<img class="media-object" src="{$avatar}" alt="{$username}">
</a>
</div>
<div class="media-body">
<h4 class="media-heading">{$model->username}</h4>
</div>
<div class="media-footer">
<div class="row">
<div class="col-xs-4 text-center">
<span class="block font-14">{$userData['following_count']}</span><br>
<small class="text-muted">关注</small>
</div><!-- /.col -->
<div class="col-xs-4 text-center">
<span class="block font-14">{$userData['follower_count']}</span><br>
<small class="text-muted">粉丝</small>
</div><!-- /.col -->
<div class="col-xs-4 text-center">
<span class="block font-14">{$userData['feed_count']}</span><br>
<small class="text-muted">文章</small>
</div><!-- /.col -->
</div>
<a class="btn btn-xs btn-success btn-follow" href="{$followUrl}">
{$followBtn}
</a>
</div>
HTML;
return $html;
}
return $this->render('/user/index', ['model' => $model]);
}
示例2: actionFollow
/**
* @param integer $id User ID
*/
public function actionFollow($id)
{
$id = intval($id);
if (Yii::$app->Request->isAjax && Yii::$app->user->id !== $id) {
if (User::getIsFollow($id)) {
//已经关注,则删除记录,取消关注
Yii::$app->db->createCommand("DELETE FROM {{%user_follow}} WHERE user_id=:user_id AND people_id=:id")->bindValues([':user_id' => Yii::$app->user->id, ':id' => $id])->execute();
Yii::$app->userData->updateKey('following_count', Yii::$app->user->id, -1);
Yii::$app->userData->updateKey('follower_count', $id, -1);
} else {
//还没有关注,则添加记录,添加关注
Yii::$app->db->createCommand()->insert('{{%user_follow}}', ['user_id' => Yii::$app->user->id, 'people_id' => $id])->execute();
Yii::$app->userData->updateKey('following_count', Yii::$app->user->id);
Yii::$app->userData->updateKey('follower_count', $id);
}
return true;
}
return false;
}