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条)

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波