And*_*son 3 forms validation silex
我有以下silex代码在完成时呈现一个简单的表单和消息:
$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(),
));
Run Code Online (Sandbox Code Playgroud)
但是在表单提交时,我会收到错误消息:
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
Run Code Online (Sandbox Code Playgroud)
我正在注册上面的ValidatorServiceProvider,所以我很难理解它可能是什么.