Skip to content

add router.request_context.base_url to cookbook entry #1916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 23, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions cookbook/console/generating_urls.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand All @@ -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

Expand All @@ -44,6 +56,7 @@ via normal web requests, since those will override the defaults.
<parameters>
<parameter key="router.request_context.host">example.org</parameter>
<parameter key="router.request_context.scheme">https</parameter>
<parameter key="router.request_context.base_url">my/path</parameter>
</parameters>
</container>

Expand All @@ -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
-------------------------------------------
Expand All @@ -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
}
Expand Down