I’m using ActiveDataProvider tu return result of comments my function in widget is
public function run()
{
$pageSize = 3;
$query = Comment::find()->andWhere(['file_id' => 47]);
$comments = $query->orderBy(['id'=> SORT_ASC]);
$count = $query->count();
$dataProvider = new ActiveDataProvider([
'query' => $comments,
'pagination' => [
'defaultPageSize' => $pageSize,
],
]);
return $this->render('indexComment', [
'dataProvider' => $dataProvider,
'fileId' => $this->file,
'objectId' => $this->object,
]);
}
I’m getting only one result but I have 7 comments with same ‘file_id’ but if I set $pageSize = 5 I get 3 results if I set my $pageSize = 6; I get only one result if I set $pageSize = 10; I get all results if I set $pageSize = 7; I get all my results If I set $pageSize = 4 I get only 3 results
I tried :
'pagination' => [
'pageSize' => $pageSize,
],
I tried :
$query = Comment::find();
$count = $query->count();
$pagination = new Pagination(['totalCount' => $count, 'defaultPageSize' => $pageSize]);
$comments = $query->offset($pagination->offset)
->limit($pagination->limit);
$dataProvider = new ActiveDataProvider([
'query' => $comments,
]);
I tried :
$query = Comment::find();
$count = $query->count();
$pagination = new Pagination(['totalCount' => $count, 'defaultPageSize' => $pageSize]);
$comments = $query->offset($pagination->offset)
->limit($pagination->limit);
$dataProvider = new ActiveDataProvider([
'query' => $comments,
'pagination' => [
'pageSize' => 3,
],
]);
My indexComment :
<?php
echo ListView::widget([
'dataProvider' => $dataProvider,
'itemOptions' => ['class' => 'comment-album-list'],
'itemView' => function ($model, $key, $index, $widget)
{
return $this->render('listcomment',['model' => $model, 'index' => $index, 'widget' => $widget, 'key' => $key, 'pageIndex' => $pageIndex]);
},
'id' => 'div-comment',
'options' => [
'tag' => 'div',
'class' => 'comment-div text-center',
'id' => 'comment-container',
],
'layout' => "{items}\n{pager}",
'pager' => [
'class' => LoadMorePager::class,
'label' => 'Load more',
'id' => 'ultra-loadmore',
],
]);
?>
My listComment :
<div>
<?= $model->message ?>
</div>
all returning same thing
I don’t understand.