Yii Framework Forum: Missing argument 1 for CDateFormatter::__construct() - Yii Framework Forum

Jump to content

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

Missing argument 1 for CDateFormatter::__construct() Rate Topic: -----

#1 User is offline   blset 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 25-February 10

Posted 25 February 2010 - 02:40 PM

hi

I put in the config main.php the entry

'dateFormatter'=>array('class'=>'CDateFormatter', 'params'=>array('fr')

),

as mentioned in other posts about using CDateFormatter

then in some view

echo Yii::app()->dateFormatter->format("EEEE",'25/02/2010') ;



I got the message
Missing argument 1 for CDateFormatter::__construct()


In fact the call to CDateFormatter constructors occurs in createComponent() method in YiiBase

the offending call is in line 209 of YiiBase and you figure out that the test there line 190-210 does not make use of params at all so the constructor fails


Anyone had this problem , how to use CDateFormatter from the config main.php ?

thanks

blset
0

#2 User is offline   blset 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 25-February 10

Posted 26 February 2010 - 07:55 AM

View Postblset, on 25 February 2010 - 02:40 PM, said:

hi

I put in the config main.php the entry

'dateFormatter'=>array('class'=>'CDateFormatter', 'params'=>array('fr')

),

as mentioned in other posts about using CDateFormatter

then in some view

echo Yii::app()->dateFormatter->format("EEEE",'25/02/2010') ;



I got the message
Missing argument 1 for CDateFormatter::__construct()


In fact the call to CDateFormatter constructors occurs in createComponent() method in YiiBase

the offending call is in line 209 of YiiBase and you figure out that the test there line 190-210 does not make use of params at all so the constructor fails


Anyone had this problem , how to use CDateFormatter from the config main.php ?

thanks

blset

0

#3 User is offline   blset 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 25-February 10

Posted 26 February 2010 - 08:01 AM

complement :

After removing anything in the config file main.php about a CDateFormatter component,

and inside a view, using Yii::app()->dateFormatter->format("EEE", $date), it works with default language English


someone could explain where does this come from ? where is the configuration for english ?
and why it does not work (see previous post) if a CDateFormatter component is declared in the config file

thanks
0

#4 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,906
  • Joined: 04-October 08
  • Location:DC, USA

Posted 26 February 2010 - 09:03 AM

CDateFormatter is not an application component. So you can't declare it in 'components' in main.php.
Without declaring it in main.php, you can directly use Yii::app()->dateFormatter because of the existence of CApplication::getDateFormatter().
The date formatter returned uses the locale as specified by Yii::app()->language.
If you want to use the date formatter for a different locale, you can use Yii::app()->getLocale('fr')->dateFormatter
2

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