Commit b29c33f5 authored by Joel Roggenkamp's avatar Joel Roggenkamp

Address bc changes from Symfony 2.8 to Symfony 3

Ref: https://github.com/silexphp/Silex/issues/1302

How is pre-Symfony3 documentation handled?  Is that a separate page or should notes on pre-Symfony3 usage be included on this page?
parent 5a7a491f
...@@ -69,6 +69,8 @@ Usage ...@@ -69,6 +69,8 @@ Usage
The FormServiceProvider provides a ``form.factory`` service. Here is a usage The FormServiceProvider provides a ``form.factory`` service. Here is a usage
example:: example::
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
$app->match('/form', function (Request $request) use ($app) { $app->match('/form', function (Request $request) use ($app) {
// some default data for when the form is displayed the first time // some default data for when the form is displayed the first time
...@@ -77,10 +79,10 @@ example:: ...@@ -77,10 +79,10 @@ example::
'email' => 'Your email', 'email' => 'Your email',
); );
$form = $app['form.factory']->createBuilder('form', $data) $form = $app['form.factory']->createBuilder(FormType::class, $data)
->add('name') ->add('name')
->add('email') ->add('email')
->add('gender', 'choice', array( ->add('gender', ChoiceType::class, array(
'choices' => array(1 => 'male', 2 => 'female'), 'choices' => array(1 => 'male', 2 => 'female'),
'expanded' => true, 'expanded' => true,
)) ))
...@@ -114,6 +116,9 @@ And here is the ``index.twig`` form template (requires ``symfony/twig-bridge``): ...@@ -114,6 +116,9 @@ And here is the ``index.twig`` form template (requires ``symfony/twig-bridge``):
If you are using the validator provider, you can also add validation to your If you are using the validator provider, you can also add validation to your
form by adding constraints on the fields:: form by adding constraints on the fields::
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;
$app->register(new Silex\Provider\ValidatorServiceProvider()); $app->register(new Silex\Provider\ValidatorServiceProvider());
...@@ -121,14 +126,14 @@ form by adding constraints on the fields:: ...@@ -121,14 +126,14 @@ form by adding constraints on the fields::
'translator.domains' => array(), 'translator.domains' => array(),
)); ));
$form = $app['form.factory']->createBuilder('form') $form = $app['form.factory']->createBuilder(FormType::class)
->add('name', 'text', array( ->add('name', TextType::class, array(
'constraints' => array(new Assert\NotBlank(), new Assert\Length(array('min' => 5))) 'constraints' => array(new Assert\NotBlank(), new Assert\Length(array('min' => 5)))
)) ))
->add('email', 'text', array( ->add('email', TextType::class, array(
'constraints' => new Assert\Email() 'constraints' => new Assert\Email()
)) ))
->add('gender', 'choice', array( ->add('gender', ChoiceType::class, array(
'choices' => array(1 => 'male', 2 => 'female'), 'choices' => array(1 => 'male', 2 => 'female'),
'expanded' => true, 'expanded' => true,
'constraints' => new Assert\Choice(array(1, 2)), 'constraints' => new Assert\Choice(array(1, 2)),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment