public static function isLiked($post_id, $user_id) { if (Like::find()->where(['post_id' => $post_id, 'user_id' => $user_id])->count() > 0) { return true; } else { return false; } }
<?php /** * Created by PhpStorm. * User: Nguyen * Date: 10/27/2015 * Time: 10:46 PM */ $this->title = 'Chi tiết bài'; $this->params['breadcrumbs'][] = $this->title; $listCmt = \common\models\Comment::find()->where(['post_id' => $model['id']])->asArray()->all(); $likeCount = \common\models\Like::find()->where(['post_id' => $model['id']])->count(); $isLiked = \common\models\Like::findOne(['post_id' => $model['id'], 'user_id' => Yii::$app->user->getId()]) != null; ?> <div class="row"> <div class="col-lg-10 col-lg-offset-1"> <!-- Box Comment --> <div class="box box-widget"> <div class="box-header with-border"> <div class="user-block"> <img class="img-circle" src="<?php if ($model['image'] != "") { echo Yii::$app->request->baseUrl . "/images/" . $model['image']; } else { echo Yii::$app->request->baseUrl . "/images/post-icon.png"; } ?> " alt="user image"> <span class="title"><a href="#"> <?php echo $model['title'];