Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii framework 2.0 multiple paginations on one page

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?

like image 334
O Connor Avatar asked Dec 10 '14 16:12

O Connor


1 Answers

You can do it by changing pageParam property of Pagination class:

$cityPagination = new Pagination([
    ...    
    'pageParam' => 'city-page',
]);
like image 119
arogachev Avatar answered Oct 25 '22 18:10

arogachev