Silex ExecutionContext :: getValidator () not found when calling handleRequest or bind

I have the following sylex code to submit a simple form and message upon completion:

$app->register(new Silex\Provider\FormServiceProvider\FormServiceProvider());
$app->register(new Silex\Provider\ValidatorServiceProvider());

$app->match('/contact', function(Request $request) use ($app) {

$form = $app['form.factory']->createBuilder('form', null)
    ->add('name', 'text', array('required' => true, 'label' => 'Name',))
    ->add('submit', 'submit')
    ->getForm();

$form->handleRequest($request);

if ($form->isValid()) {

    die('success);
}

    return $app['twig']->render('contact.html.twig', array(
        'form'   => $form->createView(),
));

      

However, when I submit the form, I get an error message:

Call to undefined method Symfony\\Component\\Validator\\ExecutionContext::getValidator() 
in /home/user/project/vendor/symfony/form/Symfony
/Component/Form/Extension/Validator/Constraints/FormValidator.php on line 56

      

I am registering the ValidatorServiceProvider as above, so I am focused on what it might be.

+3


source to share


3 answers


It looks like a Symfony bug. Backporting this commit fixed this for me.



+7


source


to fix this, update composer .json to point to symfony 2.5. 2 :

"symfony/symfony": "2.5.2",

      

instead

"symfony/symfony": "~2.5",

      

Then move composer .lock to composer.lock.bak and run



composer update symfony/symfony

      

This solved the problem for me.

Or, you can wait for symfony 2.5.4 to fix this problem:

https://github.com/symfony/symfony/issues/11580

+2


source


You must register Validator before FormServiceProvider.

0


source







All Articles