Yii Framework Forum: CFormatter parse values and be locale aware - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CFormatter parse values and be locale aware patch inside Rate Topic: -----

#1 User is offline   Rangel Reale 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 68
  • Joined: 14-January 10

Posted 31 January 2010 - 05:48 PM

On the application class there is a 'format' property that can be used to format values, but there is no corresponding methods to parse values back into PHP formats.

I suggest that the CFormatter class also include parsing functions, the same as the format ones, like parseDate, parseRaw, etc, so it could be used with a common API for both functions.

Also, the CLocale class contains all information that CFormatter could use to format the values, so to not break compatibility, I suggest the creation of a CLocaleFormatter class that formats/parses values using the locale.

Attached is a patch of a implementation I made of this, on Yii trunk.

Comments are welcome.

Attached File(s)


2

#2 User is offline   marcovtwout 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 79
  • Joined: 16-September 10
  • Location:Delft, NL

Posted 08 May 2012 - 02:54 AM

This is an old topic, but I just stumbled upon this problem now:

When using CDetailView or CGridView, the easiest way to set the appropiate display value is by setting the 'type' attribute of the column. This uses CFormatter (Yii::app()->format) which to my surprise is not locale aware.

It would be good if CFormatter was locale aware, but it's also pretty simple to change this in your application.
Open your main config and add: (example for Dutch)

'components' => array(
    (...)
        'format' => array(
		'dateFormat' => 'd-m-Y',
		'numberFormat' => array('decimals'=>null, 'decimalSeparator'=>',', 'thousandSeparator'=>'.'),
		'booleanFormat' => array('Nee', 'Ja'),
        ),
    (...)

Yii-Environment Extension - Predefine configurations for use in different environments, like development, testing, staging and production.
NetBeans IDE and Yii projects - Short directions and general tips for managing a Yii application in NetBeans IDE
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users