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
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:
+2
source to share