Skip to content

Commit 6f33b44

Browse files
committed
[HttpFoundation] update doc creation session table
1 parent 7ad8b60 commit 6f33b44

File tree

1 file changed

+58
-2
lines changed

1 file changed

+58
-2
lines changed

session.rst

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,50 @@ configuration option to tell Symfony to use this service as the session handler:
760760
;
761761
};
762762
763+
Or you can also define it directly as follows:
764+
765+
.. configuration-block::
766+
767+
.. code-block:: yaml
768+
769+
# config/packages/framework.yaml
770+
framework:
771+
session:
772+
# ...
773+
handler_id: '%env(resolve:DATABASE_URL)%'
774+
775+
.. code-block:: xml
776+
777+
<!-- config/packages/framework.xml -->
778+
<?xml version="1.0" encoding="UTF-8" ?>
779+
<container xmlns="http://symfony.com/schema/dic/services"
780+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
781+
xmlns:framework="http://symfony.com/schema/dic/symfony"
782+
xsi:schemaLocation="http://symfony.com/schema/dic/services
783+
https://symfony.com/schema/dic/services/services-1.0.xsd
784+
http://symfony.com/schema/dic/symfony
785+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
786+
787+
<framework:config>
788+
<!-- ... -->
789+
<framework:session
790+
handler-id="%env(resolve:DATABASE_URL)%"/>
791+
</framework:config>
792+
</container>
793+
794+
.. code-block:: php
795+
796+
// config/packages/framework.php
797+
use Symfony\Config\FrameworkConfig;
798+
799+
return static function (FrameworkConfig $framework) {
800+
// ...
801+
$framework->session()
802+
->handlerId('%env(resolve:DATABASE_URL)%')
803+
;
804+
};
805+
806+
763807
Configuring the Session Table and Column Names
764808
..............................................
765809

@@ -857,7 +901,13 @@ Preparing the Database to Store Sessions
857901
........................................
858902

859903
Before storing sessions in the database, you must create the table that stores
860-
the information. The session handler provides a method called
904+
the information.
905+
906+
With Doctrine installed, the session table will be automatically generated when
907+
you run the make:migration command if the database targeted by doctrine is identical to
908+
the one used by this component.
909+
910+
Or if you prefer to create the table yourself and the table has not already been created, the session handler provides a method called
861911
:method:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\PdoSessionHandler::createTable`
862912
to set up this table for you according to the database engine used::
863913

@@ -867,7 +917,9 @@ to set up this table for you according to the database engine used::
867917
// the table could not be created for some reason
868918
}
869919

870-
If you prefer to set up the table yourself, it's recommended to generate an
920+
If the table already exists an exception will be thrown.
921+
922+
If you would rather set up the table yourself, it's recommended to generate an
871923
empty database migration with the following command:
872924

873925
.. code-block:: terminal
@@ -883,6 +935,10 @@ file and run the migration with the following command:
883935
884936
.. _mysql:
885937

938+
If needed, you can also add this table to your schema by calling
939+
:method:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\PdoSessionHandler::configureSchema` method
940+
in your code.
941+
886942
MariaDB/MySQL
887943
+++++++++++++
888944

0 commit comments

Comments
 (0)