Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have the following silex code to present 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 on form submit I get presented with an error:

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 stumped to what it could be.

like image 971
Andrew Atkinson Avatar asked Mar 21 '26 08:03

Andrew Atkinson


2 Answers

It looks to be a Symfony bug. Backporting this commit fixed it for me.

like image 156
Gawain Avatar answered Mar 24 '26 03:03

Gawain


to fix it update you composer.json to specify symfony 2.5.2 :

"symfony/symfony": "2.5.2",

instead of

"symfony/symfony": "~2.5",

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

composer update symfony/symfony

That solved the problem for me.

Or you can wait for symfony 2.5.4 that should solve this problem :

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

like image 41
sonique Avatar answered Mar 24 '26 03:03

sonique



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!