Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silex FormServiceProvider could not load type "form" when using Symfony3 Components

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?

like image 339
bestattendance Avatar asked Dec 05 '22 01:12

bestattendance


1 Answers

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"
    }
}
like image 146
Igor Pantović Avatar answered Dec 06 '22 15:12

Igor Pantović