Skip to content

Commit 0746fcb

Browse files
Sgoettschkesweaverryan
authored andcommitted
Moving the console generating urls cookbook inside the sending emails cookbook.
1 parent cc049d3 commit 0746fcb

File tree

5 files changed

+41
-44
lines changed

5 files changed

+41
-44
lines changed

cookbook/console/generating_urls.rst

Lines changed: 0 additions & 39 deletions
This file was deleted.

cookbook/console/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ Console
66

77
console_command
88
usage
9-
generating_urls
109
sending_emails

cookbook/console/sending_emails.rst

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,45 @@
11
.. index::
22
single: Console; Sending emails
3+
single: Console; Generating URLs
34

4-
How to send emails in a console command
5-
=======================================
5+
How to generate URLs and send Emails from the Console
6+
=====================================================
7+
8+
Unfortunately, the command line context does not know about your VirtualHost
9+
or domain name. This means that if if you generate absolute URLs within a
10+
Console Command you'll probably end up with something like ``http://localhost/foo/bar``
11+
which is not very useful.
12+
13+
To fix this, you need to configure the "request context", which is a fancy
14+
way of saying that you need to configure your environment so that it knows
15+
what URL it should use when generating URLs.
16+
17+
There are two ways of configuring the request context: at the application level
18+
(only available in Symfony 2.1+) and per Command.
19+
20+
Configuring the Request Context per Command
21+
-------------------------------------------
22+
23+
To change it only in one command you can simply fetch the Request Context
24+
service and override its settings::
25+
26+
// src/Acme/DemoBundle/Command/DemoCommand.php
27+
28+
// ...
29+
class DemoCommand extends ContainerAwareCommand
30+
{
31+
protected function execute(InputInterface $input, OutputInterface $output)
32+
{
33+
$context = $this->getContainer()->get('router')->getContext();
34+
$context->setHost('example.com');
35+
$context->setScheme('https');
36+
37+
// ... your code here
38+
}
39+
}
40+
41+
Using Memory Spooling
42+
---------------------
643

744
Sending emails in a console command works the same way as described in the
845
:doc:`/cookbook/email/email` cookbook except if memory spooling is used.

cookbook/map.rst.inc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
* :doc:`/cookbook/console/console_command`
3030
* :doc:`/cookbook/console/usage`
31-
* :doc:`/cookbook/console/generating_urls`
3231
* :doc:`/cookbook/console/sending_emails`
3332

3433
* :doc:`/cookbook/controller/index`

redirection_map

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
/components/event_dispatcher /components/event_dispatcher/introduction
1717
/components/http_foundation /components/http_foundation/introduction
1818
/components/console /components/console/introduction
19-
/components/routing /components/routing/introduction
19+
/components/routing /components/routing/introduction
20+
/cookbook/console/generating_urls /cookbook/console/sending_emails

0 commit comments

Comments
 (0)