Symfony2日期表单类型:致命错误:在非对象上调用成员函数setLenient()

Symfony2日期表单类型:致命错误:在非对象上调用成员函数setLenient()

问题描述:

thanks to Stof on IRC i know the answer now. I just wanted to share it, in case someone stumbles upon the same problem.

The problem

When you have field type datetime:

/**
 * @ORM\Column(type="datetime", name="released_at")
 */
protected $released_at;

and in form type you use date form type:

$builder
      ->add('released_at', 'date', array(
          'widget' => 'single_text',
          'format' => 'yyyy-MM-dd',
      ));

and you're getting this error:

Fatal error: Call to a member function setLenient() on a non-object in (...)\vendor\symfony\src\Symfony\Component\Form\Extension\Core\Type\DateType.php on line 64

感谢IRC上的Stof我现在知道答案了。 我只是想分享它,万一有人偶然发现同样的问题。 p>

问题 h1>

当你有字段类型datetime: p >

  / ** 
 * @ORM \ Column(type =“datetime”,name =“released_at”)
 * / 
 nprotected $ released_at; 
  code>  
 
 

在表单类型中使用日期表单类型: p>

  $ builder 
  - > add('released_at','date'  ,array(
'widget'=>'single_text',
'format'=>'yyyy-MM-dd',
)); 
  code>  pre> 
 
  

并且您收到此错误: p>

致命错误:在(...)\中的非对象上调用成员函数setLenient() 第64行的vendor \ symfony \ src \ Symfony \ Component \ Form \ Extension \ Core \ Type \ DateType.php p> blockquote> div>

The solution is

Try this test

<?php

$formatter = new \IntlDateFormatter();

if($formatter === null)
  echo 'null!';
else
  echo 'else';

If you get null, it means your php / intl version is buggy and you need to upgrade.

In my case, I was running @ Windows 7 64bit machine, Wampserver2 with PHP 5.3.8.

Upgradeing to PHP 5.3.10 or higher did the trick.

Also if you are getting:

(..path..)\StubIntlDateFormatter::setLenient() is not implemented. Please install the 'intl' extension for full localization capabilities.

upgrade to Symfony 2.0.16.

Cheers and once again, TYVM Stof!

I have two configurations, each with a different application: - Windows 7 64bit machine, Wampserver2 with PHP 5.3.8 with Symfony 2.0.15 installed using composer - Windows 7 64bit machine, Wampserver2 with PHP 5.3.8 with Symfony 2.1-RC1 installed from zip with vendors

On the first configuration I had the error:

Fatal error: Call to a member function format() on a non-object in C:\MyProject\vendor\symfony\src\Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToLocalizedStringTransformer.php on line 97

On the second configuration I had the error:

Fatal error: Call to a member function setLenient() on a non-object in C:\MyProjectSf2.1\vendor\symfony\symfony\src\Symfony\Component\Form\Extension\Core\Type\DateType.php on line 81

I upgraded only PHP from 5.3.8 to 5.3.13 in my WAMP2 installation using the files provided at the following place: http://www.anindya.com/php-5-4-3-and-php-5-3-13-x64-64-bit-for-windows/ PHP 5.3.13 (Thread Safe) + Fixed curl extensions

and it fixed the issues on both applications !

A big thanks to Anindya for his effort offering 64bits compiled version of the PHP DLL, I didn't find an other 64bits version anywhere else ! ( and as far as I have seen (I compared the version using Beyond Compare), it was his 5.3.8 64bits thread safe version included in the Wamp2 version I have ;)

Best regards, Christophe

This happens if you don't have correct parameteres in your php.ini... Check if you have a correct configuration of time zone in your php.ini as "Europe/Brussels" (case sensitive)