Tuesday, July 3, 2012

how Configuring widget defaults works in YII

A Yii web application provides a bunch of components. One of them is a widget factory that
since Yii 1.1.3 can be used to set widget defaults.
1. Let's use it to set pageSize application-wide. We will need to edit the application
configuration file main.php as follows:
return array(

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

),
),

),
);
2. Now, the default value for CLinkPager's pageSize will be 15, so if we omit this
parameter for all the application CLinkPagers then it will be 15, application-wide.
3. Moreover, we still can override the pageSize value for a specific widget:
<?$this->widget('CLinkPager', array(
'pages' => $pages,
'pageSize' => 5,
))?>
This works much like the CSS cascade. You are setting the default overall style in an external
file, but are still able to override this through inline styles for individual widgets.

1 comment:

  1. CLinkPager does not have a 'pageSize' property. 'pageSize' property is in 'CPagination' (not a widget).

    ReplyDelete