V
V
Vyacheslav2017-04-28 21:52:36
Yii
Vyacheslav, 2017-04-28 21:52:36

dataProvider pagination bug or feature?

Hi all!
I have a banal SqlDataProvider
from the model returns new SqlDataProvider([ .. ]);
so here is an interesting feature or bug:
if you do this:

$data['items'] = Catalogs::catalogItems($data['category']['catalog_code'])->getModels();
$data['pagination'] = Catalogs::catalogItems($data['category']['catalog_code'])->getPagination();

then everything is OK, pagination is displayed \ working
request returns
_pagination:yii\data\BaseDataProvider:private] => yii\data\Pagination Object
        (
            [totalCount] => 632
        )

but if you do it like this:
$items = Catalogs::catalogItems($data['category']['catalog_code']);
$data['items'] = $items->getModels();
$data['pagination'] = $items->getPagination();

then pagination disappears =) and the array with data is in place and the data will be displayed
, but the query returns
_pagination:yii\data\BaseDataProvider:private] => yii\data\Pagination Object
        (
            [totalCount] => 0
        )

Is it supposed to be like this and am I doing something wrong?
By the way, if you do this:
$items = Catalogs::catalogItems($data['category']['catalog_code']);
$data['items'] = [];
$data['pagination'] = $items->getPagination();

those. do not take an array from the value that is returned, then everything is also ok, totalCount will be 632 =)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav, 2017-04-28
@nskarl

Figured it out myself.
'totalCount' => $count needs to be added not only to pagination' => [] , but also to go higher.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question