本文整理匯總了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;
}