启用intl.so扩展后,表单上的PHP错误消息

时间:2011-05-31 14:43:25

标签: php frameworks symfony intl

I've attached an image of the error message I am getting. At first my date drop down select for users birthday was working fine. But I finally installed and enabled the intl extension that symfony2 was asking for and now I get that error message. Any idea what the problem could be?

这是我的控制器:

<?php

namespace Home\JoinBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Home\JoinBundle\Entity\User;

class DefaultController extends Controller
{
    public function indexAction()
    {
        $user = new User;
        $user->fname;
        $user->lname;
        $user->bday;

         $form = $this->get('form.factory')
                 ->createBuilder('form', $user)
                 ->add('fname', 'text', array('label' => 'First Name: '))
                 ->add('lname', 'text', array('label' => 'Last Name: '))
                 ->add('bday', 'birthday',  array('input' => 'array', 'widget' => 'choice'))
                 ->getForm();


        return $this->render('HomeJoinBundle:Default:index.html.twig', array('form' => $form->createView()));
    }

}

1 个答案:

答案 0 :(得分:1)

奇怪的是,默认值不起作用,但尝试一下(默认情况下应该做同样的事情,详见http://symfony.com/doc/current/reference/forms/types/birthday.html

$dater = new \IntlDateFormatter();
$form = $this->get('form.factory')
             ->createBuilder('form', $user)
             ->add('fname', 'text', array('label' => 'First Name: '))
             ->add('lname', 'text', array('label' => 'Last Name: '))
             ->add('bday', 'birthday',  array('input' => 'array', 'widget' => 'choice', 'months' => $dater))
             ->getForm();