Class CFormatter
CFormatter provides a set of commonly used data formatting methods.
The formatting methods provided by CFormatter are all named in the form of
formatXyz
. The behavior of some of them may be configured via the
properties of CFormatter. For example, by configuring CFormatter::$dateFormat
, one
may control how CFormatter::formatDate()
formats the value into a date string.
For convenience, CFormatter also implements the mechanism of calling
formatting methods with their shortcuts (called types). In particular, if a
formatting method is named formatXyz
, then its shortcut method is
xyz
(case-insensitive). For example, calling <span
class="php-var">$formatter</span>-><span
class="php-keyword2">date</span>(<span
class="php-var">$value</span>)
is equivalent to calling
<span
class="php-var">$formatter</span>->formatDate(<span
class="php-var">$value</span>)
.
- raw: the attribute value will not be changed at all.
- text: the attribute value will be HTML-encoded when rendering.
- ntext: the
CFormatter::formatNtext()
method will be called to format the attribute value as a HTML-encoded plain text with newlines converted as the HTML <br /> or <p></p> tags. - html: the attribute value will be purified and then returned.
- date: the
CFormatter::formatDate()
method will be called to format the attribute value as a date. - time: the
CFormatter::formatTime()
method will be called to format the attribute value as a time. - datetime: the
CFormatter::formatDatetime()
method will be called to format the attribute value as a date with time. - boolean: the
CFormatter::formatBoolean()
method will be called to format the attribute value as a boolean display. - number: the
CFormatter::formatNumber()
method will be called to format the attribute value as a number display. - email: the
CFormatter::formatEmail()
method will be called to format the attribute value as a mailto link. - image: the
CFormatter::formatImage()
method will be called to format the attribute value as an image tag where the attribute value is the image URL. - url: the
CFormatter::formatUrl()
method will be called to format the attribute value as a hyperlink where the attribute value is the URL. - size: the
CFormatter::formatSize()
method will be called to format the attribute value, interpreted as a number of bytes, as a size in human readable form.
By default, CApplication
registers CFormatter
as an
application component whose ID is 'format'. Therefore, one may call
Yii::app()->format->boolean(<span
class="php-num">1</span>)
. You might want to replace this
component with CLocalizedFormatter
to enable formatting based on the
current locale settings.
- CComponent
- CApplicationComponent implements IApplicationComponent
- CFormatter
Direct known subclasses
CLocalizedFormatterCopyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 1.1.0
Located at x2engine/framework/utils/CFormatter.php
public
mixed
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
#
formatNtext( mixed $value, boolean $paragraphs = false, boolean $removeEmptyParagraphs = true )
Formats the value as a HTML-encoded plain text and converts newlines with HTML <br /> or <p></p> tags. |
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
protected
integer
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
|
|
public
string
|
#
formatSize( integer $value, boolean $verbose = false )
Formats the value in bytes as a size in human readable form. |
getIsInitialized(),
init()
|
public
string
|
$dateFormat | 'Y/m/d' |
#
the format string to be used to format a date using PHP date() function. Defaults to 'Y/m/d'. |
public
string
|
$timeFormat | 'h:i:s A' |
#
the format string to be used to format a time using PHP date() function. Defaults to 'h:i:s A'. |
public
string
|
$datetimeFormat | 'Y/m/d h:i:s A' |
#
the format string to be used to format a date and time using PHP date() function. Defaults to 'Y/m/d h:i:s A'. |
public
array
|
$numberFormat | array('decimals'=>null, 'decimalSeparator'=>null, 'thousandSeparator'=>null) |
#
the format used to format a number with PHP number_format() function. Three elements may be specified: "decimals", "decimalSeparator" and "thousandSeparator". They correspond to the number of digits after the decimal point, the character displayed as the decimal point and the thousands separator character. |
public
array
|
$booleanFormat | array('No','Yes') |
#
the text to be displayed when formatting a boolean value. The first element
corresponds to the text display for false, the second element for true. Defaults
to |
public
array
|
$htmlPurifierOptions | array() |
#
the options to be passed to CHtmlPurifier instance used in this class.
CHtmlPurifier is used in |
public
array
|
$sizeFormat | array(
'base'=>1024,
'decimals'=>2,
'decimalSeparator'=>null,
) |
#
the format used to format size (bytes). Three elements may be specified: "base", "decimals" and "decimalSeparator". They correspond to the base at which a kilobyte is calculated (1000 or 1024 bytes per kilobyte, defaults to 1024), the number of digits after the decimal point (defaults to 2) and the character displayed as the decimal point. "decimalSeparator" is available since version 1.1.13 |
$behaviors
|
public
|
$htmlPurifier |
#
The HTML purifier instance. |
$isInitialized
|