Yii 2.0 framework multiple pagination on one page

Working with Yii framework 2.0 I tried using the pagination feature and linkpager widget following the 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 am using the following code.

<?= LinkPager::widget(['pagination' => $pagination]) ?>

      

Now I want to add another pagination function and LinkPager widget for another City model . In the actionIndex () method I am following the existing code, just create a City object and a new Pagination object and return it to the view. In the view, I re-enable the LinkPager widget with a different pagination $ paginationCity variable . When I click on the page number, I saw the page = xx query string in the url. I notice that it is used for both Country and City models . How do I use multiple pagination on one page?

+3


source to share


1 answer


You can do this by changing the pageParam property of the Pagination

class:



$cityPagination = new Pagination([
    ...    
    'pageParam' => 'city-page',
]);

      

+3


source







All Articles