diff --git a/cookbook/configuration/pdo_session_storage.rst b/cookbook/configuration/pdo_session_storage.rst index 7955873d878..5b335c802d4 100644 --- a/cookbook/configuration/pdo_session_storage.rst +++ b/cookbook/configuration/pdo_session_storage.rst @@ -217,3 +217,85 @@ For MSSQL, the statement might look like the following: ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] + +Doctrine DBAL Session Storage +----------------------------- + +Symfony applications can also use a Doctrine DBAL based session storage. This +alternative implementation is very similar to the ``PdoSessionHandler`` explained +above, but uses a Doctrine connection and thus also works with non-PDO-based +drivers like mysqli and OCI8. + +The only significant disadvantage of the Doctrine DBAL session storage comparing +it with ``PdoSessionHandler`` is that you can only configure the name of the +table used to store sessions but not its column names. + +DBAL Session Storage configuration example: + +.. configuration-block:: + + .. code-block:: yaml + + # app/config/config.yml + framework: + session: + # ... + handler_id: session.handler.dbal + + parameters: + # ... + dbal_session_table: session + + # app/config/services.yml + services: + # ... + session.handler.dbal: + class: Symfony\Bridge\Doctrine\HttpFoundation\DbalSessionHandler + arguments: ["@doctrine.dbal.default_connection", "%dbal_session_table%"] + + .. code-block:: xml + + + + + + + + + + session + + + + + + + + %dbal_session_table% + + + + .. code-block:: php + + // app/config/config.php + use Symfony\Component\DependencyInjection\Definition; + use Symfony\Component\DependencyInjection\Reference; + + $container->loadFromExtension('framework', array( + // ... + 'session' => array( + // ... + 'handler_id' => 'session.handler.dbal', + ), + )); + + // ... + $container->setParameter('pdo.dbal_session_table', 'sess'); + + // app/config/services.php + // ... + $storageDefinition = new Definition('Symfony\Bridge\Doctrine\HttpFoundation\DbalSessionHandler', array( + new Reference('doctrine.dbal.default_connection'), + '%dbal_session_table%', + )); + $container->setDefinition('session.handler.dbal', $storageDefinition);