| Package | system.utils |
|---|---|
| Inheritance | class CLocalizedFormatter » CFormatter » CApplicationComponent » CComponent |
| Implements | IApplicationComponent |
| Since | 1.1.14 |
| Source Code | framework/utils/CLocalizedFormatter.php |
'format' => array(
'class' => 'CLocalizedFormatter',
),
| Property | Type | Description | Defined By |
|---|---|---|---|
| behaviors | array | the behaviors that should be attached to this component. | CApplicationComponent |
| booleanFormat | array | the text to be displayed when formatting a boolean value. | CFormatter |
| dateFormat | string | the width of the date pattern. | CLocalizedFormatter |
| datetimeFormat | string | the format string to be used to format a date and time using PHP date() function. | CFormatter |
| htmlPurifier | CHtmlPurifier | the HTML purifier instance | CFormatter |
| htmlPurifierOptions | array | the options to be passed to CHtmlPurifier instance used in this class. | CFormatter |
| isInitialized | boolean | Checks if this application component has been initialized. | CApplicationComponent |
| locale | CLocale | $locale the locale currently used for formatting values | CLocalizedFormatter |
| numberFormat | array | the format used to format a number with PHP number_format() function. | CFormatter |
| sizeFormat | array | the format used to format size (bytes). | CFormatter |
| timeFormat | string | the width of the time pattern. | CLocalizedFormatter |
| Method | Description | Defined By |
|---|---|---|
| __call() | Calls the format method when its shortcut is invoked. | CFormatter |
| __get() | Returns a property value, an event handler list or a behavior based on its name. | CComponent |
| __isset() | Checks if a property value is null. | CComponent |
| __set() | Sets value of a component property. | CComponent |
| __unset() | Sets a component property to be null. | CComponent |
| asa() | Returns the named behavior object. | CComponent |
| attachBehavior() | Attaches a behavior to this component. | CComponent |
| attachBehaviors() | Attaches a list of behaviors to the component. | CComponent |
| attachEventHandler() | Attaches an event handler to an event. | CComponent |
| canGetProperty() | Determines whether a property can be read. | CComponent |
| canSetProperty() | Determines whether a property can be set. | CComponent |
| detachBehavior() | Detaches a behavior from the component. | CComponent |
| detachBehaviors() | Detaches all behaviors from the component. | CComponent |
| detachEventHandler() | Detaches an existing event handler. | CComponent |
| disableBehavior() | Disables an attached behavior. | CComponent |
| disableBehaviors() | Disables all behaviors attached to this component. | CComponent |
| enableBehavior() | Enables an attached behavior. | CComponent |
| enableBehaviors() | Enables all behaviors attached to this component. | CComponent |
| evaluateExpression() | Evaluates a PHP expression or callback under the context of this component. | CComponent |
| format() | Formats a value based on the given type. | CFormatter |
| formatBoolean() | Formats the value as a boolean. | CLocalizedFormatter |
| formatDate() | Formats the value as a date using the locales date formatter. | CLocalizedFormatter |
| formatDatetime() | Formats the value as a date and time using the locales date formatter. | CLocalizedFormatter |
| formatEmail() | Formats the value as a mailto link. | CFormatter |
| formatHtml() | Formats the value as HTML text without any encoding. | CFormatter |
| formatImage() | Formats the value as an image tag. | CFormatter |
| formatNtext() | Formats the value as a HTML-encoded plain text and converts newlines with HTML <br /> or | CFormatter |
| formatNumber() | Formats the value as a number using the locales number formatter. | CLocalizedFormatter |
| formatRaw() | Formats the value as is without any formatting. | CFormatter |
| formatSize() | Formats the value in bytes as a size in human readable form. | CFormatter |
| formatText() | Formats the value as a HTML-encoded plain text. | CFormatter |
| formatTime() | Formats the value as a time using the locales date formatter. | CLocalizedFormatter |
| formatUrl() | Formats the value as a hyperlink. | CFormatter |
| getEventHandlers() | Returns the list of attached event handlers for an event. | CComponent |
| getHtmlPurifier() | Returns the HTML purifier instance | CFormatter |
| getIsInitialized() | Checks if this application component has been initialized. | CApplicationComponent |
| getLocale() | Returns $locale the locale currently used for formatting values | CLocalizedFormatter |
| hasEvent() | Determines whether an event is defined. | CComponent |
| hasEventHandler() | Checks whether the named event has attached handlers. | CComponent |
| hasProperty() | Determines whether a property is defined. | CComponent |
| init() | Initializes the application component. | CApplicationComponent |
| raiseEvent() | Raises an event. | CComponent |
| setLocale() | Set the locale to use for formatting values. | CLocalizedFormatter |
| Method | Description | Defined By |
|---|---|---|
| normalizeDateValue() | Normalizes an expression as a timestamp. | CFormatter |
the width of the date pattern. It can be 'full', 'long', 'medium' and 'short'. Defaults to 'medium'.
$locale the locale currently used for formatting values
the width of the time pattern. It can be 'full', 'long', 'medium' and 'short'. Defaults to 'medium'.
|
public string formatBoolean(mixed $value)
| ||
| $value | mixed | the value to be formatted |
| {return} | string | the formatted result |
public function formatBoolean($value)
{
return $value ? Yii::t('yii','Yes') : Yii::t('yii','No');
}
Formats the value as a boolean.
|
public string formatDate(mixed $value)
| ||
| $value | mixed | the value to be formatted |
| {return} | string | the formatted result |
public function formatDate($value)
{
return $this->getLocale()->dateFormatter->formatDateTime($this->normalizeDateValue($value), $this->dateFormat, null);
}
Formats the value as a date using the locales date formatter.
|
public string formatDatetime(mixed $value)
| ||
| $value | mixed | the value to be formatted |
| {return} | string | the formatted result |
public function formatDatetime($value)
{
return $this->getLocale()->dateFormatter->formatDateTime($this->normalizeDateValue($value), $this->dateFormat, $this->timeFormat);
}
Formats the value as a date and time using the locales date formatter.
|
public string formatNumber(mixed $value)
| ||
| $value | mixed | the value to be formatted |
| {return} | string | the formatted result |
public function formatNumber($value)
{
return $this->getLocale()->numberFormatter->formatDecimal($value);
}
Formats the value as a number using the locales number formatter.
|
public string formatTime(mixed $value)
| ||
| $value | mixed | the value to be formatted |
| {return} | string | the formatted result |
public function formatTime($value)
{
return $this->getLocale()->dateFormatter->formatDateTime($this->normalizeDateValue($value), null, $this->timeFormat);
}
Formats the value as a time using the locales date formatter.
|
public CLocale getLocale()
| ||
| {return} | CLocale | $locale the locale currently used for formatting values |
public function getLocale()
{
if($this->_locale === null) {
$this->setLocale(Yii::app()->locale);
}
return $this->_locale;
}
|
public void setLocale(CLocale|string $locale)
| ||
| $locale | CLocale|string | an instance of CLocale or a locale ID |
public function setLocale($locale)
{
if(is_string($locale))
$locale=CLocale::getInstance($locale);
$this->sizeFormat['decimalSeparator']=$locale->getNumberSymbol('decimal');
$this->_locale=$locale;
}
Set the locale to use for formatting values.
Signup or Login in order to comment.