20.11.2014 Views

O Guia Definitivo do Yii 1.1

O Guia Definitivo do Yii 1.1

O Guia Definitivo do Yii 1.1

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

then the basic theme will be in effect, which means the application's layout will use the one<br />

under the directory themes/basic/views/layouts, and the site's index view will use the one<br />

under themes/basic/views/site. In case a view file is not found in the theme, it will fall back<br />

to the one under the protected/views directory.<br />

Theming Widgets<br />

Starting from version <strong>1.1</strong>.5, views used by a widget can also be themed. In particular,<br />

when we callCWidget::render() to render a widget view, <strong>Yii</strong> will attempt to search under the<br />

theme folder as well as the widget view folder for the desired view file.<br />

To theme the view xyz for a widget whose class name is Foo, we should first create a<br />

folder named Foo (same as the widget class name) under the currently active theme's<br />

view folder. If the widget class is namespaced (available in PHP 5.3.0 or above), such as<br />

\app\widgets\Foo, we should create a folder named app_widgets_Foo. That is, we replace<br />

the namespace separators with the underscore characters.<br />

We then create a view file named xyz.php under the newly created folder. To this end, we<br />

should have a file themes/basic/views/Foo/xyz.php, which will be used by the widget to<br />

replace its original view, if the currently active theme is basic.<br />

Customizing Widgets Globally<br />

Note: this feature has been available since version <strong>1.1</strong>.3.<br />

When using a widget provided by third party or <strong>Yii</strong>, we often need to customize it for<br />

specific needs. For example, we may want to change the value of<br />

CLinkPager::maxButtonCount from 10 (default) to 5. We can accomplish this by passing<br />

the initial property values when calling CBaseController::widget to create a widget.<br />

However, it becomes troublesome to <strong>do</strong> so if we have to repeat the same customization in<br />

every place we use CLinkPager.<br />

$this->widget('CLinkPager', array(<br />

'pages'=>$pagination,<br />

'maxButtonCount'=>5,<br />

'cssFile'=>false,<br />

));<br />

Using the global widget customization feature, we only need to specify these initial values<br />

in a single place, i.e., the application configuration. This makes the customization of<br />

widgets more manageable.<br />

To use the global widget customization feature, we need to configure the widgetFactory as<br />

follows:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!