Yii2 - how to set the main pagination pageSizeLimit configuration?

I want to set the main pageSizeLimit configuration parameter to the Pagination class.

Example: (/backend/config/main.php)

'pagination' => [
        'class' => 'yii\data\Pagination',
        [
            'pageSizeLimit' => [1, 1000],
        ]
    ],

But it does not work. So how to set default values ​​for the whole site? Thank you very much!

+4
source share
2 answers

For this purpose, you can use the dependency injection container.

Define the default value in the config boot section:

\Yii::$container->set('yii\data\Pagination', [
    'pageSizeLimit' => [1, 1000],
]);

More about this in the guide https://github.com/yiisoft/yii2/blob/master/docs/guide/concept-configurations.md

+4
source

Pagination, \yii\data\Pagination, pageSizeLimit , . .

namespace app\components;

class Pagination extends \yii\data\Pagination
{
    $defaultPageSize = 100;
    $pageSizeLimit = [1, 1000];
}

:

$dataProvider = new ActiveDataProvider([
    'query' => $query,
    'pagination' => [
        'class' => '\app\components\Pagination'
    ],
]);
+3

Source: https://habr.com/ru/post/1611704/


All Articles