O Guia Definitivo do Yii 1.1
O Guia Definitivo do Yii 1.1
O Guia Definitivo do Yii 1.1
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
The CDateFormatter class mainly provides two methods to format a UNIX timestamp.<br />
• format: this method formats the given UNIX timestamp into a string according to a<br />
customized pattern (e.g. $dateFormatter->format('yyyy-MM-dd',$timestamp)).<br />
• formatDateTime: this method formats the given UNIX timestamp into a string<br />
according to a pattern predefined in the target locale data (e.g. short format of date,<br />
long format of time).<br />
Number Formatting<br />
Like data and time, numbers may also be formatted differently in different countries or<br />
regions. Number formatting includes decimal formatting, currency formatting and<br />
percentage formatting. <strong>Yii</strong> providesCNumberFormatter for these tasks.<br />
To get the number formatter associated with the target locale of the whole application, we<br />
can access the numberFormatter property of the application.<br />
The following methods are provided by CNumberFormatter to format an integer or <strong>do</strong>uble<br />
value.<br />
• format: this method formats the given number into a string according to a customized<br />
pattern (e.g.$numberFormatter->format('#,##0.00',$number)).<br />
• formatDecimal: this method formats the given number using the decimal pattern<br />
predefined in the target locale data.<br />
• formatCurrency: this method formats the given number and currency code using the<br />
currency pattern predefined in the target locale data.<br />
• formatPercentage: this method formats the given number using the percentage<br />
pattern predefined in the target locale data.<br />
Sintaxe Alternativa de Templates<br />
<strong>Yii</strong> allows developers to use their own favorite template syntax (e.g. Pra<strong>do</strong>, Smarty) to<br />
write controller or widget views. This is achieved by writing and installing a viewRenderer<br />
application component. The view renderer intercepts the invocations of<br />
CBaseController::renderFile, compiles the view file with customized template syntax, and<br />
renders the compiling results.<br />
Info: It is recommended to use customized template syntax only when writing views<br />
that are less likely to be reused. Otherwise, people who are reusing the views would be<br />
forced to use the same customized template syntax in their applications.<br />
In the following, we introduce how to use CPra<strong>do</strong>ViewRenderer, a view renderer that<br />
allows developers to use the template syntax similar to that in Pra<strong>do</strong> framework. For<br />
people who want to develop their own view renderers, CPra<strong>do</strong>ViewRenderer is a good<br />
reference.<br />
Using CPra<strong>do</strong>ViewRenderer<br />
To use CPra<strong>do</strong>ViewRenderer, we just need to configure the application as follows: