@@ -760,6 +760,50 @@ configuration option to tell Symfony to use this service as the session handler:
760
760
;
761
761
};
762
762
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
+
763
807
Configuring the Session Table and Column Names
764
808
..............................................
765
809
@@ -857,7 +901,13 @@ Preparing the Database to Store Sessions
857
901
........................................
858
902
859
903
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
861
911
:method: `Symfony\\ Component\\ HttpFoundation\\ Session\\ Storage\\ Handler\\ PdoSessionHandler::createTable `
862
912
to set up this table for you according to the database engine used::
863
913
@@ -867,7 +917,9 @@ to set up this table for you according to the database engine used::
867
917
// the table could not be created for some reason
868
918
}
869
919
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
871
923
empty database migration with the following command:
872
924
873
925
.. code-block :: terminal
@@ -883,6 +935,10 @@ file and run the migration with the following command:
883
935
884
936
.. _mysql :
885
937
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
+
886
942
MariaDB/MySQL
887
943
+++++++++++++
888
944
0 commit comments