Greetings, I want to make the number of articles on one page - dynamic (so that the user chooses), but I can’t figure out exactly how to do it. I am writing on the basic template. Here is the paginator code in the controller:

if($AllPosts) { $pages = new Pagination(['totalCount' => $AllPosts->count(), 'pageSize' => $postPerPage]); $posts = $AllPosts->offset($pages->offset) ->limit($pages->limit) ->all(); return $this->render('index', [ 'posts' => $posts, 'pages' => $pages, ]); } 

Here is the call from the view:

 <?= \yii\widgets\LinkPager::widget([ 'pagination' => $pages ]); ?> 

    1 answer 1

    You need to make a form on the page with the record, which will indicate the number of records, or drop-down, which will be a better solution. A select in a drop-down will change the URL, for example, the page-size parameter. (Ie, you should have the following URL : ...\news\?pageSize=COUNT ).

    Next in the controller you do

     $pageSize = \Yii::$app->request->get('pageSize'); 

    After you declared Pagination :

     $pages = $pagination->setPageSize($pageSize); 

    Described in general terms. For more details, see the documentation.