Commit 163be526 authored by Fabien Potencier's avatar Fabien Potencier

minor #1306 Address bc changes from Symfony 2.8 to Symfony 3 (bestattendance)

This PR was merged into the 2.0.x-dev branch.

Discussion
----------

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?

Commits
-------

b29c33f5 Address bc changes from Symfony 2.8 to Symfony 3
parents 9c90d349 b29c33f5
...@@ -69,7 +69,9 @@ Usage ...@@ -69,7 +69,9 @@ 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
$data = array( $data = array(
...@@ -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('billing_plan', 'choice', array( ->add('billing_plan', ChoiceType::class, array(
'choices' => array(1 => 'free', 2 => 'small_business', 3 => 'corporate'), 'choices' => array(1 => 'free', 2 => 'small_business', 3 => 'corporate'),
'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('billing_plan', 'choice', array( ->add('billing_plan', ChoiceType::class, array(
'choices' => array(1 => 'free', 2 => 'small_business', 3 => 'corporate'), 'choices' => array(1 => 'free', 2 => 'small_business', 3 => 'corporate'),
'expanded' => true, 'expanded' => true,
'constraints' => new Assert\Choice(array(1, 2, 3)), 'constraints' => new Assert\Choice(array(1, 2, 3)),
......
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