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!
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
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'
],
]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With