[Yii Framework] Set the default parameter of widgets for the whole application

Here we will use CLinkPager for example.

 

when using CLinkPager widget, we always follow this way:

<?$this->widget(‘CLinkPager’, array(
'pages' => $pages,
'pageSize' => 15,
))?>

Here we set it to display 15 items per page. But if we have many action view page with CLinkPager,

we just copy and parse the code as below? can we set the default value of 'pageSize'?

 

Yes, it is! Thanks to Yii, we can do that in this way, we need to edit application configuration file 

main.php:

return array(
...
  'components'=>array(
    'widgetFactory'=>array(
      'widgets'=>array(
        'CLinkPager'=>array(
          'pageSize'=>15,
        ),
      ...
      ),
    ),
    ...
  ),
);

 

Have fun with Yii! 

 

posted @ 2012-01-04 16:02  DavidHHuan  阅读(442)  评论(1编辑  收藏  举报