1
1
.. index ::
2
2
single: Console; Generating URLs
3
3
4
- How to generate URLs with a custom host in Console Commands
4
+ How to generate URLs with a custom Host in Console Commands
5
5
===========================================================
6
6
7
- The command line context does not know about your VirtualHost or domain name,
8
- therefore if you generate absolute URLs within a Console Command you generally
9
- end up with something like ``http://localhost/foo/bar `` which is not very
10
- useful.
7
+ Unfortunately, the command line context does not know about your VirtualHost
8
+ or domain name. This means that if if you generate absolute URLs within a
9
+ Console Command you'll probably end up with something like ``http://localhost/foo/bar ``
10
+ which is not very useful.
11
11
12
- There are two ways of configuring the request context, at the application level
12
+ To fix this, you need to configure the "request context", which is a fancy
13
+ way of saying that you need to configure your environment so that it knows
14
+ what URL it should use when generating URLs.
15
+
16
+ There are two ways of configuring the request context: at the application level
13
17
and per Command.
14
18
15
19
Configuring the Request Context globally
@@ -31,8 +35,6 @@ via normal web requests, since those will override the defaults.
31
35
32
36
.. code-block :: xml
33
37
34
- <!-- app/config/parameters.xml -->
35
-
36
38
<?xml version =" 1.0" encoding =" UTF-8" ?>
37
39
38
40
<container xmlns =" http://symfony.com/schema/dic/services"
@@ -54,11 +56,11 @@ Configuring the Request Context per Command
54
56
-------------------------------------------
55
57
56
58
To change it only in one command you can simply fetch the Request Context
57
- service and override its settings:
58
-
59
- .. code-block :: php
59
+ service and override its settings::
60
60
61
61
// src/Acme/DemoBundle/Command/DemoCommand.php
62
+ // ...
63
+
62
64
class DemoCommand extends ContainerAwareCommand
63
65
{
64
66
protected function execute(InputInterface $input, OutputInterface $output)
@@ -67,7 +69,7 @@ service and override its settings:
67
69
$context->setHost('example.com');
68
70
$context->setScheme('https');
69
71
70
- // your code here
72
+ // ... your code here
71
73
}
72
74
}
73
75
0 commit comments