protected function findModel($id) { if (($model = \dektrium\user\models\Profile::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionAddcomment() { if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; $data = Yii::$app->request->post(); $comment = $data['comment']; $commentedOn = $data['commentedOn']; $model = new CommentsContent(); $model->comment = $comment; $model->commentedOn = $commentedOn; $model->commentedBy = \Yii::$app->user->identity->getId(); $model->commentedAt = time(); if ($model->save()) { $profile = \dektrium\user\models\Profile::findOne(['user_id' => $model->commentedBy]); return ['image' => $profile->name, 'comment' => $comment, 'commentedOn' => $commentedOn, 'commentedBy' => User::findOne(['id' => \Yii::$app->user->identity->getId()])->username, 'commentedAt' => Yii::t('user', '{0, date}', time())]; } } }
use yii\helpers\Html; ?> <div id="post-div-<?php echo $id; ?> " class="pre-scrollable"> <div class="card-panel horizontal-listing comments-section"> <?php foreach ($models as $model) { ?> <div class="row hoverable"> <div class="col-sm-2"> <?php //$user=\dektrium\user\models\User::findOne($model->commentedBy); $profile = \dektrium\user\models\Profile::findOne(['user_id' => $model->commentedBy]); ?> <?php echo Html::img('@web/images/' . $profile->name, ['class' => 'z-depth-1', 'style' => 'width:132%;height:103px;']); ?> </div> <div class="col-sm-10" style="padding-left: 32px;"> <a href="#"> <h6 class="title"><?php echo \dektrium\user\models\User::findOne(['id' => $model->commentedBy])->username; ?> </h6> </a> <i class="fa fa-clock-o"><?php echo Yii::t('user', '{0, date}', $model->commentedAt); ?>