Skip to content

Commit d3ba62f

Browse files
move parameter configuration into separate section of the article
1 parent 4048e97 commit d3ba62f

File tree

1 file changed

+55
-30
lines changed

1 file changed

+55
-30
lines changed

cookbook/configuration/mongodb_session_storage.rst

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@ need to change/add some parameters in the main configuration file:
2525
cookie_lifetime: 2592000 # optional, it is set to 30 days here
2626
gc_maxlifetime: 2592000 # optional, it is set to 30 days here
2727
28-
parameters:
29-
# ...
30-
mongo.session.options:
31-
database: session_db # your MongoDB database name
32-
collection: session # your MongoDB collection name
33-
mongodb_host: 1.2.3.4 # your MongoDB server's IP
34-
mongodb_username: my_username
35-
mongodb_password: my_password
36-
3728
services:
3829
# ...
3930
mongo_client:
@@ -68,19 +59,6 @@ need to change/add some parameters in the main configuration file:
6859
/>
6960
</framework:config>
7061
71-
<parameters>
72-
<parameter key="mongo.session.options" type="collection">
73-
<!-- your MongoDB database name -->
74-
<parameter key="database">session_db</parameter>
75-
<!-- your MongoDB collection name -->
76-
<parameter key="collection">session</parameter>
77-
</parameter>
78-
<!-- your MongoDB server's IP -->
79-
<parameter key="mongodb_host">1.2.3.4</parameter>
80-
<parameter key="mongodb_username">my_username</parameter>
81-
<parameter key="mongodb_password">my_password</parameter>
82-
</parameters>
83-
8462
<services>
8563
<service id="mongo_client" class="MongoClient">
8664
<!-- if using a username and password -->
@@ -110,14 +88,6 @@ need to change/add some parameters in the main configuration file:
11088
),
11189
));
11290
113-
$container->setParameter('mongo.session.options', array(
114-
'database' => 'session_db', // your MongoDB database name
115-
'collection' => 'session', // your MongoDB collection name
116-
));
117-
$container->setParameter('mongodb_host', '1.2.3.4'); // your MongoDB server's IP
118-
$container->setParameter('mongodb_username', 'my_username');
119-
$container->setParameter('mongodb_password', 'my_password');
120-
12191
$container->setDefinition('mongo_client', new Definition('MongoClient', array(
12292
// if using a username and password
12393
array('mongodb://%mongodb_username%:%mongodb_password%@%mongodb_host%:27017'),
@@ -130,6 +100,61 @@ need to change/add some parameters in the main configuration file:
130100
array(new Reference('mongo_client'), '%mongo.session.options%')
131101
));
132102
103+
The parameters used above should be defined somewhere in your application, often in your main
104+
parameters configuration:
105+
106+
.. configuration-block::
107+
108+
.. code-block:: yaml
109+
110+
# app/config/parameters.yml
111+
parameters:
112+
# ...
113+
mongo.session.options:
114+
database: session_db # your MongoDB database name
115+
collection: session # your MongoDB collection name
116+
mongodb_host: 1.2.3.4 # your MongoDB server's IP
117+
mongodb_username: my_username
118+
mongodb_password: my_password
119+
120+
.. code-block:: xml
121+
122+
<?xml version="1.0" encoding="UTF-8"?>
123+
<container xmlns="http://symfony.com/schema/dic/services"
124+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance"
125+
xmlns:framework="http://symfony.com/schema/dic/symfony"
126+
xsi:schemaLocation="http://symfony.com/schema/dic/services
127+
http://symfony.com/schema/dic/services/services-1.0.xsd
128+
http://symfony.com/schema/dic/symfony
129+
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
130+
131+
<parameters>
132+
<parameter key="mongo.session.options" type="collection">
133+
<!-- your MongoDB database name -->
134+
<parameter key="database">session_db</parameter>
135+
<!-- your MongoDB collection name -->
136+
<parameter key="collection">session</parameter>
137+
</parameter>
138+
<!-- your MongoDB server's IP -->
139+
<parameter key="mongodb_host">1.2.3.4</parameter>
140+
<parameter key="mongodb_username">my_username</parameter>
141+
<parameter key="mongodb_password">my_password</parameter>
142+
</parameters>
143+
</container>
144+
145+
.. code-block:: php
146+
147+
use Symfony\Component\DependencyInjection\Reference;
148+
use Symfony\Component\DependencyInjection\Definition;
149+
150+
$container->setParameter('mongo.session.options', array(
151+
'database' => 'session_db', // your MongoDB database name
152+
'collection' => 'session', // your MongoDB collection name
153+
));
154+
$container->setParameter('mongodb_host', '1.2.3.4'); // your MongoDB server's IP
155+
$container->setParameter('mongodb_username', 'my_username');
156+
$container->setParameter('mongodb_password', 'my_password');
157+
133158
Setting Up the MongoDB Collection
134159
---------------------------------
135160

0 commit comments

Comments
 (0)