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

发布于 2024-11-11 14:01:15 字数 899 浏览 5 评论 0原文

这是我的控制器:

<?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()));
    }

}

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?

Here is my controller:

<?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()));
    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懷念過去 2024-11-18 14:01:15

奇怪的是默认值不起作用,但尝试一下(默认情况下应该做同样的事情,如 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();

It's strange that the default value isn't working, but try this out (doing the same thing it should be doing by default as detailed in 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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文