Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 - how to set main config param pagination pageSizeLimit?

I want set main config param pageSizeLimit in class Pagination.

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

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

But it not working. So, how to set defaults for the entire site? Thank you very much!

like image 397
KhacNha Avatar asked Oct 15 '15 04:10

KhacNha


2 Answers

You can use dependency injection container for this purpose.

Define default parameter's value in bootstrapping section of config:

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

Read more on this in the guide https://github.com/yiisoft/yii2/blob/master/docs/guide/concept-configurations.md

like image 186
aalgogiver Avatar answered Oct 27 '22 23:10

aalgogiver


Make your own Pagination class inherited from \yii\data\Pagination and in it set pageSizeLimit to whatever value you want. Then use this class in your data providers.

namespace app\components;

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

Then in your data providers:

$dataProvider = new ActiveDataProvider([
    'query' => $query,
    'pagination' => [
        'class' => '\app\components\Pagination'
    ],
]);
like image 34
Beowulfenator Avatar answered Oct 27 '22 23:10

Beowulfenator