public function actionDetail() { $id = Yii::$app->request->get('id'); $article = new Article(); $detail = $article->getDetail($id); $comment = new Comment(); $comments = $comment->getComments($id); $visitor = new Visitor(); echo $this->render('detail', ['detail' => $detail, 'comments' => $comments, 'visitor' => $visitor]); }
/** * Displays a single Post model. * @param integer $id * @return mixed */ public function actionView($id) { $post = $this->findModel($id); $model = new Comment(); $user = ""; if (!Yii::$app->user->isGuest) { $uid = Yii::$app->user->identity->getId(); $get_user = \dektrium\user\models\User::getUser($uid)->getModels()[0]['username']; $user = \dektrium\user\models\User::getUser($uid)->getModels()[0]['group']; if (isset($_POST['Comment'])) { // print_r($_POST['Comment']['text']); $model = new Comment(); $model->author = $get_user; $model->post_id = $id; $model->user_id = $uid; $model->date = date("Y-m-d h:i:s"); $model->text = $_POST['Comment']['text']; $model->rating_plus = 0; $model->rating_minus = 0; $model->save(); } } $getTags = Post_tags::getTags($id); // print_r($getTags->getModels()); $postData = Post::getOnePost($id); $commentData = Comment::getComments($id); return $this->render('/post/view', ['post' => $post, 'postData' => $postData, 'commentData' => $commentData, 'model' => $model, 'tags' => $getTags, 'user' => $user]); }