system system.base system.caching system.caching.dependencies system.collections system.console system.db system.db.ar system.db.schema system.db.schema.cubrid system.db.schema.mssql system.db.schema.mysql system.db.schema.oci system.db.schema.pgsql system.db.schema.sqlite system.gii system.i18n system.i18n.gettext system.logging system.test system.utils system.validators system.web system.web.actions system.web.auth system.web.filters system.web.form system.web.helpers system.web.renderers system.web.services system.web.widgets system.web.widgets.captcha system.web.widgets.pagers zii.behaviors zii.widgets zii.widgets.grid zii.widgets.jui

CLocalizedFormatter

system.utils
继承 class CLocalizedFormatter » CFormatter » CApplicationComponent » CComponent
实现 IApplicationComponent
可用自 1.1.14
源码 framework/utils/CLocalizedFormatter.php
CLocalizedFormatter provides a set of commonly used data formatting methods based on the current locale settings.

It provides the same functionality as CFormatter, but overrides all the settings for booleanFormat, datetimeFormat and numberFormat with the values for the current locale. Because of this you are not able to configure these properties for CLocalizedFormatter directly. Date and time format can be adjusted by setting dateFormat and timeFormat.

It uses CApplication::locale by default but you can set a custom locale by using setLocale-method.

For a list of recognizable format types, and details on how to call the formatter methods, see CFormatter documentation.

To replace the application component 'format', which is registered by CApplication by default, you can put this in your application 'components' config: 'format' => array( 'class' => 'CLocalizedFormatter', ),

公共属性

隐藏继承的属性

属性类型描述被定义在
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

公共方法

隐藏继承的方法

方法描述被定义在
__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

受保护的方法

隐藏继承的方法

方法描述被定义在
normalizeDateValue() Normalizes an expression as a timestamp. CFormatter

属性详情

dateFormat 属性
public string $dateFormat;

the width of the date pattern. It can be 'full', 'long', 'medium' and 'short'. Defaults to 'medium'.

locale 属性
public CLocale getLocale()
public void setLocale(CLocale|string $locale)

$locale the locale currently used for formatting values

timeFormat 属性
public string $timeFormat;

the width of the time pattern. It can be 'full', 'long', 'medium' and 'short'. Defaults to 'medium'.

方法详情

formatBoolean() 方法
public string formatBoolean(mixed $value)
$value mixed the value to be formatted
{return} string the formatted result
源码: framework/utils/CLocalizedFormatter.php#79 (显示)
public function formatBoolean($value)
{
    return 
$value Yii::t('yii','Yes') : Yii::t('yii','No');
}

Formats the value as a boolean.

参见

formatDate() 方法
public string formatDate(mixed $value)
$value mixed the value to be formatted
{return} string the formatted result
源码: framework/utils/CLocalizedFormatter.php#91 (显示)
public function formatDate($value)
{
    return 
$this->getLocale()->dateFormatter->formatDateTime($this->normalizeDateValue($value), $this->dateFormatnull);
}

Formats the value as a date using the locales date formatter.

formatDatetime() 方法
public string formatDatetime(mixed $value)
$value mixed the value to be formatted
{return} string the formatted result
源码: framework/utils/CLocalizedFormatter.php#116 (显示)
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.

formatNumber() 方法
public string formatNumber(mixed $value)
$value mixed the value to be formatted
{return} string the formatted result
源码: framework/utils/CLocalizedFormatter.php#127 (显示)
public function formatNumber($value)
{
    return 
$this->getLocale()->numberFormatter->formatDecimal($value);
}

Formats the value as a number using the locales number formatter.

formatTime() 方法
public string formatTime(mixed $value)
$value mixed the value to be formatted
{return} string the formatted result
源码: framework/utils/CLocalizedFormatter.php#103 (显示)
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.

getLocale() 方法
public CLocale getLocale()
{return} CLocale $locale the locale currently used for formatting values
源码: framework/utils/CLocalizedFormatter.php#65 (显示)
public function getLocale()
{
    if(
$this->_locale === null) {
        
$this->setLocale(Yii::app()->locale);
    }
    return 
$this->_locale;
}

setLocale() 方法
public void setLocale(CLocale|string $locale)
$locale CLocale|string an instance of CLocale or a locale ID
源码: framework/utils/CLocalizedFormatter.php#54 (显示)
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.