Commit de9c57a9 authored by Fabien Potencier's avatar Fabien Potencier

minor #1461 Update the documentation (SpacePossum)

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

Discussion
----------

Update the documentation

Hi all!

I've made a few minor changes to the docs ~to get those back into shape.
However I could use help finishing the `routing.rst`, this describes the `RoutingServiceProvider`.
The provider is powerful and awesome, but I struggle getting any good copy in there.
So if you have time please help out :)~

Commits
-------

75dcc3b9 Update documentation.
parents 002a6a6e 75dcc3b9
......@@ -45,8 +45,7 @@ With a dedicated PDO service
$app['session.storage.handler'] = function () use ($app) {
return new PdoSessionHandler(
$app['pdo'],
$app['session.db_options'],
$app['session.storage.options']
$app['session.db_options']
);
};
......@@ -62,19 +61,16 @@ have to make another database connection, simply pass the getWrappedConnection m
$app->register(new Silex\Provider\SessionServiceProvider());
$app['session.db_options'] = array(
$app['session.storage.handler'] = function () use ($app) {
return new PdoSessionHandler(
$app['db']->getWrappedConnection(),
array(
'db_table' => 'session',
'db_id_col' => 'session_id',
'db_data_col' => 'session_value',
'db_lifetime_col' => 'session_lifetime',
'db_time_col' => 'session_time',
);
$app['session.storage.handler'] = function () use ($app) {
return new PdoSessionHandler(
$app['db']->getWrappedConnection(),
$app['session.db_options'],
$app['session.storage.options']
)
);
};
......
......@@ -51,9 +51,13 @@ Included providers
There are a few providers that you get out of the box. All of these are within
the ``Silex\Provider`` namespace:
* :doc:`AssetServiceProvider <providers/asset>`
* :doc:`CsrfServiceProvider <providers/csrf>`
* :doc:`DoctrineServiceProvider <providers/doctrine>`
* :doc:`FormServiceProvider <providers/form>`
* :doc:`HttpCacheServiceProvider <providers/http_cache>`
* :doc:`HttpFragmentServiceProvider <providers/http_fragment>`
* :doc:`LocaleServiceProvider <providers/locale>`
* :doc:`MonologServiceProvider <providers/monolog>`
* :doc:`RememberMeServiceProvider <providers/remember_me>`
* :doc:`SecurityServiceProvider <providers/security>`
......@@ -64,6 +68,7 @@ the ``Silex\Provider`` namespace:
* :doc:`TranslationServiceProvider <providers/translation>`
* :doc:`TwigServiceProvider <providers/twig>`
* :doc:`ValidatorServiceProvider <providers/validator>`
* :doc:`VarDumperServiceProvider <providers/var_dumper>`
.. note::
......
......@@ -47,12 +47,12 @@ Registering
composer require symfony/form
If you are going to use the validation extension with forms, you must also
add a dependency to the ``symfony/config`` and ``symfony/translation``
add a dependency to the ``symfony/validator`` and ``symfony/config``
components:
.. code-block:: bash
composer require symfony/validator symfony/config symfony/translation
composer require symfony/validator symfony/config
If you want to use forms in your Twig templates, you can also install the
Symfony Twig Bridge. Make sure to install, if you didn't do that already,
......@@ -60,7 +60,7 @@ Registering
.. code-block:: bash
composer require symfony/twig-bridge symfony/config symfony/translation
composer require symfony/twig-bridge
Usage
-----
......@@ -68,8 +68,9 @@ Usage
The FormServiceProvider provides a ``form.factory`` service. Here is a usage
example::
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
$app->match('/form', function (Request $request) use ($app) {
// some default data for when the form is displayed the first time
......@@ -82,9 +83,12 @@ example::
->add('name')
->add('email')
->add('billing_plan', ChoiceType::class, array(
'choices' => array(1 => 'free', 2 => 'small_business', 3 => 'corporate'),
'choices' => array('free' => 1, 'small business' => 2, 'corporate' => 3),
'expanded' => true,
))
->add('submit', SubmitType::class, [
'label' => 'Save',
])
->getForm();
$form->handleRequest($request);
......@@ -115,9 +119,10 @@ 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
form by adding constraints on the fields::
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Validator\Constraints as Assert;
$app->register(new Silex\Provider\ValidatorServiceProvider());
......@@ -133,10 +138,13 @@ form by adding constraints on the fields::
'constraints' => new Assert\Email()
))
->add('billing_plan', ChoiceType::class, array(
'choices' => array(1 => 'free', 2 => 'small_business', 3 => 'corporate'),
'choices' => array('free' => 1, 'small business' => 2, 'corporate' => 3),
'expanded' => true,
'constraints' => new Assert\Choice(array(1, 2, 3)),
))
->add('submit', SubmitType::class, [
'label' => 'Save',
])
->getForm();
You can register form types by extending ``form.types``::
......@@ -194,11 +202,15 @@ Traits
``Silex\Application\FormTrait`` adds the following shortcuts:
* **form**: Creates a FormBuilder instance.
* **form**: Creates a FormBuilderInterface instance.
* **namedForm**: Creates a FormBuilderInterface instance (named).
.. code-block:: php
$app->form($data);
$app->namedForm($name, $data, $options, $type);
For more information, consult the `Symfony Forms documentation
<http://symfony.com/doc/2.8/book/forms.html>`_.
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