@@ -22,10 +22,17 @@ Configuring the Request Context globally
22
22
.. versionadded :: 2.1
23
23
The ``host `` and ``scheme `` parameters are available since Symfony 2.1
24
24
25
+ .. versionadded: 2.2
26
+
27
+ The base_url parameter is available since Symfony 2.2
28
+
25
29
To configure the Request Context - which is used by the URL Generator - you can
26
30
redefine the parameters it uses as default values to change the default host
27
- (localhost) and scheme (http). Note that this does not impact URLs generated
28
- via normal web requests, since those will override the defaults.
31
+ (localhost) and scheme (http). Starting with Symfony 2.2 you can also configure
32
+ the base path if Symfony is not running in the root directory.
33
+
34
+ Note that this does not impact URLs generated via normal web requests, since those
35
+ will override the defaults.
29
36
30
37
.. configuration-block ::
31
38
@@ -35,6 +42,7 @@ via normal web requests, since those will override the defaults.
35
42
parameters :
36
43
router.request_context.host : example.org
37
44
router.request_context.scheme : https
45
+ router.request_context.base_url : my/path
38
46
39
47
.. code-block :: xml
40
48
@@ -47,6 +55,7 @@ via normal web requests, since those will override the defaults.
47
55
<parameters >
48
56
<parameter key =" router.request_context.host" >example.org</parameter >
49
57
<parameter key =" router.request_context.scheme" >https</parameter >
58
+ <parameter key =" router.request_context.base_url" >my/path</parameter >
50
59
</parameters >
51
60
</container >
52
61
@@ -55,6 +64,7 @@ via normal web requests, since those will override the defaults.
55
64
// app/config/config_test.php
56
65
$container->setParameter('router.request_context.host', 'example.org');
57
66
$container->setParameter('router.request_context.scheme', 'https');
67
+ $container->setParameter('router.request_context.base_url', 'my/path');
58
68
59
69
Configuring the Request Context per Command
60
70
-------------------------------------------
@@ -72,6 +82,7 @@ service and override its settings::
72
82
$context = $this->getContainer()->get('router')->getContext();
73
83
$context->setHost('example.com');
74
84
$context->setScheme('https');
85
+ $context->setBaseUrl('my/path');
75
86
76
87
// ... your code here
77
88
}
0 commit comments