Skip to content

Commit b503567

Browse files
committed
Improved the example to generate URLs in the console
1 parent 4787f7c commit b503567

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

console/request_context.rst

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,20 @@ Configuring the Request Context per Command
6565
To change it only in one command you can simply fetch the Request Context
6666
from the ``router`` service and override its settings::
6767

68-
// src/AppBundle/Command/DemoCommand.php
69-
70-
// ...
71-
class DemoCommand extends ContainerAwareCommand
72-
{
73-
protected function execute(InputInterface $input, OutputInterface $output)
74-
{
75-
$context = $this->getContainer()->get('router')->getContext();
76-
$context->setHost('example.com');
77-
$context->setScheme('https');
78-
$context->setBaseUrl('my/path');
79-
80-
// ... your code here
81-
}
82-
}
68+
// src/AppBundle/Command/DemoCommand.php
69+
70+
// ...
71+
class DemoCommand extends ContainerAwareCommand
72+
{
73+
protected function execute(InputInterface $input, OutputInterface $output)
74+
{
75+
$router = $this->getContainer()->get('router');
76+
$context = $router->getContext();
77+
$context->setHost('example.com');
78+
$context->setScheme('https');
79+
$context->setBaseUrl('my/path');
80+
81+
$url = $router->generate('route-name', array('param-name' => 'param-value'));
82+
// ...
83+
}
84+
}

0 commit comments

Comments
 (0)