Skip to content

Commit 41b2eb8

Browse files
committed
minor #3693 Tweak to Absolute URL generation (weaverryan)
This PR was merged into the 2.3 branch. Discussion ---------- Tweak to Absolute URL generation | Q | A | |----------------|------| | Doc fix | yes | | New docs | no | | Applies to | 2.3 | | Fixed tickets | #3573 | This updates how we describe URL generation. After #3573, it occurs to me that if you're looking here for a reference, you'll look for the first spot where absolute URLs are discussed and try to use it. So why not put the controller/PHP version and template version of doing this in the same spot. Cheers! Commits ------- 007a54f Fixing typo thanks to @xabbuh 873706c Moved the section about generating absolute URLs down
2 parents bd473db + 007a54f commit 41b2eb8

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

book/routing.rst

+23-25
Original file line numberDiff line numberDiff line change
@@ -1192,29 +1192,6 @@ In an upcoming section, you'll learn how to generate URLs from inside templates.
11921192
11931193
For more information, see the documentation for that bundle.
11941194

1195-
.. index::
1196-
single: Routing; Absolute URLs
1197-
1198-
Generating Absolute URLs
1199-
~~~~~~~~~~~~~~~~~~~~~~~~
1200-
1201-
By default, the router will generate relative URLs (e.g. ``/blog``). To generate
1202-
an absolute URL, simply pass ``true`` to the third argument of the ``generate()``
1203-
method::
1204-
1205-
$this->get('router')->generate('blog_show', array('slug' => 'my-blog-post'), true);
1206-
// http://www.example.com/blog/my-blog-post
1207-
1208-
.. note::
1209-
1210-
The host that's used when generating an absolute URL is the host of
1211-
the current ``Request`` object. This is detected automatically based
1212-
on server information supplied by PHP. When generating absolute URLs for
1213-
scripts run from the command line, you'll need to manually set the desired
1214-
host on the ``RequestContext`` object::
1215-
1216-
$this->get('router')->getContext()->setHost('www.example.com');
1217-
12181195
.. index::
12191196
single: Routing; Generating URLs in a template
12201197

@@ -1227,7 +1204,7 @@ But if you pass extra ones, they will be added to the URI as a query string::
12271204
$this->get('router')->generate('blog', array('page' => 2, 'category' => 'Symfony'));
12281205
// /blog/2?category=Symfony
12291206

1230-
Generating URLs from a template
1207+
Generating URLs from a Template
12311208
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12321209

12331210
The most common place to generate a URL is from within a template when linking
@@ -1250,7 +1227,20 @@ a template helper function:
12501227
Read this blog post.
12511228
</a>
12521229

1253-
Absolute URLs can also be generated.
1230+
.. index::
1231+
single: Routing; Absolute URLs
1232+
1233+
Generating Absolute URLs
1234+
~~~~~~~~~~~~~~~~~~~~~~~~
1235+
1236+
By default, the router will generate relative URLs (e.g. ``/blog``). From
1237+
a controller, simply pass ``true`` to the third argument of the ``generateUrl()``
1238+
method::
1239+
1240+
$this->generateUrl('blog_show', array('slug' => 'my-blog-post'), true);
1241+
// http://www.example.com/blog/my-blog-post
1242+
1243+
From a template, it looks like this:
12541244

12551245
.. configuration-block::
12561246

@@ -1268,6 +1258,14 @@ Absolute URLs can also be generated.
12681258
Read this blog post.
12691259
</a>
12701260

1261+
.. note::
1262+
1263+
The host that's used when generating an absolute URL is the host of
1264+
the current ``Request`` object. This is detected automatically. But if
1265+
you generate absolute URLs for scripts run from the command line, this
1266+
won't work. But don't worry! Just see :doc:`/cookbook/console/sending_emails`
1267+
for details.
1268+
12711269
Summary
12721270
-------
12731271

0 commit comments

Comments
 (0)