diff --git a/cookbook/console/generating_urls.rst b/cookbook/console/generating_urls.rst index 1e3ef5ee0dc..a441ab8c89b 100644 --- a/cookbook/console/generating_urls.rst +++ b/cookbook/console/generating_urls.rst @@ -19,10 +19,21 @@ and per Command. Configuring the Request Context globally ---------------------------------------- +.. versionadded: 2.1 + + The host and scheme parameters are available since Symfony 2.1 + +.. versionadded: 2.2 + + The base_url parameter is available since Symfony 2.2 + To configure the Request Context - which is used by the URL Generator - you can redefine the parameters it uses as default values to change the default host -(localhost) and scheme (http). Note that this does not impact URLs generated -via normal web requests, since those will override the defaults. +(localhost) and scheme (http). Starting with Symfony 2.2 you can also configure +the base path if Symfony is not running in the root directory. + +Note that this does not impact URLs generated via normal web requests, since those +will override the defaults. .. configuration-block:: @@ -32,6 +43,7 @@ via normal web requests, since those will override the defaults. parameters: router.request_context.host: example.org router.request_context.scheme: https + router.request_context.base_url: my/path .. code-block:: xml @@ -44,6 +56,7 @@ via normal web requests, since those will override the defaults. example.org https + my/path @@ -52,6 +65,7 @@ via normal web requests, since those will override the defaults. // app/config/config_test.php $container->setParameter('router.request_context.host', 'example.org'); $container->setParameter('router.request_context.scheme', 'https'); + $container->setParameter('router.request_context.base_url', 'my/path'); Configuring the Request Context per Command ------------------------------------------- @@ -69,6 +83,7 @@ service and override its settings:: $context = $this->getContainer()->get('router')->getContext(); $context->setHost('example.com'); $context->setScheme('https'); + $context->setBaseUrl('my/path'); // ... your code here }