Commit 7e5e1f88 authored by Fabien Potencier's avatar Fabien Potencier

merged branch ChrisRiddell/session-patch1 (PR #539)

This PR was squashed before being merged into the master branch (closes #539).

Commits
-------

7df7761c Example for DoctrineServiceProvider in session cookbook

Discussion
----------

Example for DoctrineServiceProvider in session cookbook

Adds an example for using the DoctrineServiceProvider with PdoSessionHandler.

---------------------------------------------------------------------------

by GromNaN at 2012-11-09T12:27:02Z

You should add section titles as the cookbook gives 2 ways to do the same thing.

---------------------------------------------------------------------------

by ChrisRiddell at 2012-11-09T12:35:50Z

@GromNaN Sorry still new to this what do you mean by section titles?

---------------------------------------------------------------------------

by GromNaN at 2012-11-09T12:43:52Z

The page contains 2 titles named "Example".
* 1st: name it "With a dedicated PDO service"
* 2nd: name it "Using the DoctrineServiceProvider" & move the text you added after the 2nd title.

---------------------------------------------------------------------------

by GromNaN at 2012-11-09T15:03:24Z

👍
parents 960f097b 7df7761c
...@@ -15,8 +15,8 @@ has multiple storage handlers and one of them uses PDO to store sessions, ...@@ -15,8 +15,8 @@ has multiple storage handlers and one of them uses PDO to store sessions,
To use it, replace the ``session.storage.handler`` service in your application To use it, replace the ``session.storage.handler`` service in your application
like explained below. like explained below.
Example With a dedicated PDO service
------- ----------------------------
.. code-block:: php .. code-block:: php
...@@ -28,7 +28,7 @@ Example ...@@ -28,7 +28,7 @@ Example
$app['pdo.user'] = 'myuser'; $app['pdo.user'] = 'myuser';
$app['pdo.password'] = 'mypassword'; $app['pdo.password'] = 'mypassword';
$app['pdo.db_options'] = array( $app['session.db_options'] = array(
'db_table' => 'session', 'db_table' => 'session',
'db_id_col' => 'session_id', 'db_id_col' => 'session_id',
'db_data_col' => 'session_value', 'db_data_col' => 'session_value',
...@@ -46,7 +46,34 @@ Example ...@@ -46,7 +46,34 @@ Example
$app['session.storage.handler'] = $app->share(function () use ($app) { $app['session.storage.handler'] = $app->share(function () use ($app) {
return new PdoSessionHandler( return new PdoSessionHandler(
$app['pdo'], $app['pdo'],
$app['pdo.db_options'], $app['session.db_options'],
$app['session.storage.options']
);
});
Using the DoctrineServiceProvider
---------------------------------
When using the :doc:`DoctrineServiceProvider </providers/doctrine>` You don't
have to make another database connection, simply pass the getWrappedConnection method.
.. code-block:: php
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;
$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_time_col' => 'session_time',
);
$app['session.storage.handler'] = $app->share(function () use ($app) {
return new PdoSessionHandler(
$app['db']->getWrappedConnection(),
$app['session.db_options'],
$app['session.storage.options'] $app['session.storage.options']
); );
}); });
...@@ -62,4 +89,4 @@ PdoSessionStorage needs a database table with 3 columns: ...@@ -62,4 +89,4 @@ PdoSessionStorage needs a database table with 3 columns:
You can find examples of SQL statements to create the session table in the You can find examples of SQL statements to create the session table in the
`Symfony2 cookbook `Symfony2 cookbook
<http://symfony.com/doc/current/cookbook/configuration/pdo_session_storage.html>`_ <http://symfony.com/doc/current/cookbook/configuration/pdo_session_storage.html#example-sql-statements>`_
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