Commit 75dcc3b9 authored by SpacePossum's avatar SpacePossum

Update documentation.

parent 002a6a6e
......@@ -6,7 +6,7 @@ often desirable and allows you to configure them independently, allowing for fin
grained control of where your logging goes and in what detail.
This simple example allows you to quickly configure several monolog instances,
using the bundled handler, but each with a different channel.
using the bundled handler, but each with a different channel.
.. code-block:: php
......
......@@ -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(
'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']
array(
'db_table' => 'session',
'db_id_col' => 'session_id',
'db_data_col' => 'session_value',
'db_lifetime_col' => 'session_lifetime',
'db_time_col' => 'session_time',
)
);
};
......
......@@ -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::
......@@ -93,7 +98,7 @@ Providers must implement the ``Pimple\ServiceProviderInterface``::
This is very straight forward, just create a new class that implements the
register method. In the ``register()`` method, you can define services on the
application which then may make use of other services and parameters.
application which then may make use of other services and parameters.
.. tip::
......@@ -149,13 +154,13 @@ Here is an example of such a provider::
public function boot(Application $app)
{
// do something
// do something
}
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
{
$dispatcher->addListener(KernelEvents::REQUEST, function(FilterResponseEvent $event) use ($app) {
// do something
// do something
});
}
}
......
......@@ -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