Ejemplo n.º 1
0
 public function actionView($title)
 {
     $articleId = explode('-', $title);
     $articleModel = new ArticleComments();
     $model = new ArticleComments();
     $model->user_id = Yii::$app->user->id;
     $article = $this->findModel($articleId[1]);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->render('view', ['model' => $article, 'articleComments' => $articleModel, 'articleCommentsList' => ArticleComments::getArticleComments($articleId[1]), 'popularPosts' => Article::getPopularPosts(), 'author' => Profile::findOne(['user_id' => $article['psychologist_id']])]);
     }
     if ($articleId[1]) {
         $articleModel->article_id = $articleId[1];
         return $this->render('view', ['model' => $article, 'articleComments' => $articleModel, 'articleCommentsList' => ArticleComments::getArticleComments($articleId[1]), 'popularPosts' => Article::getPopularPosts(), 'author' => Profile::findOne(['user_id' => $article['psychologist_id']])]);
     }
 }
Ejemplo n.º 2
0
 public static function getArticleComments($articleId)
 {
     $query = ArticleComments::find();
     //$query->addSelect('article_comments.*,profile.firstname,profile.lastname');
     $query->with('commentOwner');
     //$query->innerJoin('profile', 'profile.user_id=article_comments.user_id');
     $query->andFilterWhere(['article_id' => $articleId]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 6], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     return $dataProvider;
 }