F
F
Forxxx2019-04-23 22:56:29
Yii
Forxxx, 2019-04-23 22:56:29

Yii2-comments how to change order by?

I'm using yii2mod/yii2-comments
I need to change the default sorting of comments from new to old.
The parameter for sorting when displaying the widget was not found in the documentation.
How to change comment sorting to SORT-DESC?
If this is not possible - how to redefine the extension module in order to make your own edits to it? Or is it possible to override one getTree function in which the request is formed?
In fact, the issue is solved by changing SORT_ASC to SORT-DESC in the getTree function of the CommentModel.php model.
But I want to do it right, and not make changes to the extension source files

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2019-04-23
@Forxxx

Good evening.
Try like this

<?php echo \yii2mod\comments\widgets\Comment::widget([
      'model' => $model,
      'dataProviderConfig' => [
          'pagination' => [
              'pageSize' => 10
          ],
          'sort' => [
              'defaultOrder' => ['id' => 'SORT_DESC']
          ]
      ]
]); ?>

Sort by id in reverse order, from newest to oldest.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question