Working with Yii framework 2.0 I tried to use the pagination feature and linkpager widget, following Yii documentation.
Below is my controller.
public function actionIndex()
{
$query = Country::find();
$pagination = new Pagination([
'defaultPageSize' => 5,
'totalCount' => $query->count(),
]);
$countries = $query->orderBy('name')
->offset($pagination->offset)
->limit($pagination->limit)
->all();
return $this->render('index', [
'countries' => $countries,
'pagination' => $pagination,
]);
}
In my index view, I use the following code.
<?= LinkPager::widget(['pagination' => $pagination]) ?>
Now I want to add one more pagination feature and LinkPager widget for another model City. In the actionIndex() method I follow the existing code, just create an object of City and an object of new Pagination and return it to the view. In the view I include LinkPager widget once again with another pagination variable $paginationCity. When I click on a pagination number I saw the query string page=xx in the URL. I notice that it is being used for both models Country and City. How can I use multiple pagination on one same page?
You can do it by changing pageParam property of Pagination
class:
$cityPagination = new Pagination([
...
'pageParam' => 'city-page',
]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With