function replyComments($idcomments) { $data = Comments::find()->with('iduser0')->where(['parent' => $idcomments])->all(); foreach ($data as $val) { echo "<u>" . $val['iduser0']['username'] . "</u> replied<br/>" . "<b>" . $val['description'] . "</b><br/>"; } }
public function run() { $model = new Comments(); $query = Comments::find()->where(['class_name' => $this->class_name, 'item_id' => $this->item_id])->orderBy('id DESC'); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]); echo $this->render('commentsWidget/view', ['dataProvider' => $dataProvider]); echo $this->render('commentsWidget/_form', ['model' => $model]); }
public function actionView() { if (User::isAdmin(Yii::$app->user->identity->username)) { $link = new ActiveDataProvider(['query' => Comments::find(), 'pagination' => ['pageSize' => 50]]); return $this->render('view', compact('link')); } else { throw new ForbiddenHttpException('У вас нет прав администратора!', 404); } }
public function getComments($id) { $query = Comments::find()->where(['status' => 10, 'article_id' => $id]); if (!$query->count()) { return false; } $pagination = new Pagination(['defaultPageSize' => 20, 'totalCount' => $query->count(), 'forcePageParam' => false, 'pageSizeParam' => false]); $comments = $query->orderBy(['id' => SORT_DESC])->offset($pagination->offset)->limit($pagination->limit)->all(); return ['comments' => $comments, 'pagination' => $pagination]; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Comments::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['idcomments' => $this->idcomments, 'idtodo' => $this->idtodo, 'iduser' => $this->iduser, 'parent' => $this->parent, 'cdate' => $this->cdate, 'mdate' => $this->mdate]); $query->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Comments::find()->with('article'); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['status' => SORT_ASC, 'id' => SORT_DESC]], 'pagination' => ['pagesize' => 15, 'forcePageParam' => false, 'pageSizeParam' => false]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'created' => $this->created, 'approved' => $this->updated, 'article_id' => $this->article_id, 'status' => $this->status]); $query->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Comments::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'parent_id' => $this->parent_id, 'datetime' => $this->datetime, 'item_id' => $this->item_id]); $query->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'class_name', $this->class_name]); return $dataProvider; }
/** * Displays a single Post model. * @param integer $id * @return mixed */ public function actionView($id) { $comments = new Comments(); $comments->id_post = $id; return $this->render('view', ['model' => $this->findModel($id), 'comments' => $comments, 'commentsProvider' => new ActiveDataProvider(['query' => Comments::find()->where(['id_post' => $id])])]); }
</div> <br> <div class="meta"> <p>Автор: <b><?php echo $model->author->username; ?> </b>; Дата публикации: <?php echo $model->publish_date; ?> ; Категория: <?php echo Html::a($model->category->title, ['category/view', 'id' => $model->category->id]); ?> </p> </div> <h4>Коментарии:</h4> <?php echo ListView::widget(['dataProvider' => new ActiveDataProvider(['query' => Comments::find()->where(['id_post' => $model->id])]), 'itemView' => function ($comments) { return $this->render('_comments', ['model' => $comments]); }, 'emptyText' => 'Комментариев нету']); ?> <h3>Добавить комментарий:</h3> <?php echo $this->render('/comments/_form', ['model' => $comments, 'actionComments' => '/comments/create']); ?> </div>
/** * Lists all Comments models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Comments::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }