dqhdz04240 2016-01-07 19:09 采纳率: 0%
浏览 51
已采纳

使用Symfony3组件时,Silex FormServiceProvider无法加载“form”类型

When trying to build a form I receive this error:

InvalidArgumentException in FormRegistry.php line 87: Could not load type "form"

I've registered the FormServiceProvider, TranslationServicerProvider, and ValidatorServiceProvider.

Here is the relevant part of my code:

        $this->_form = $this->_app['form.factory']->createBuilder('form', $this->_map())
        ->add('firstName', 'text', [
            'constraints' => [new Assert\NotBlank()]
        ])
        ->add('lastName', 'text', [
            'constraints' => [new Assert\NotBlank()]
        ])
        ->add('email', 'text', [
            'constraints' => [new Assert\Email()]
        ])
        ->getForm();

Here are version numbers of the related components that I'm using:

silex/silex v1.3.4 The PHP micro-framework based on the Symfony Components symfony/security-core
v3.0.1 Symfony Security Component - Core Library symfony/security-csrf v3.0.1 Symfony Security Component - CSRF Library symfony/translation v3.0.1 Symfony Translation Component symfony/twig-bridge v3.0.1 Symfony Twig Bridge symfony/validator v3.0.1 Symfony Validator Component symfony/form v3.0.1

I was able to do this successfully in previous versions of Silex; did something break or am I missing something?

  • 写回答

3条回答 默认 最新

  • dousong1992 2016-01-07 19:26
    关注

    It seems that latest version of Silex does not work with Symfony Forms v3. To make it work, replace requires in your composer file to:

    {
        "require": {
            "silex/silex": "^1.3",
            "symfony/form": "~2.3",
            "symfony/security-csrf": "~2.3"
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog