@@ -1192,29 +1192,6 @@ In an upcoming section, you'll learn how to generate URLs from inside templates.
1192
1192
1193
1193
For more information, see the documentation for that bundle.
1194
1194
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
-
1218
1195
.. index ::
1219
1196
single: Routing; Generating URLs in a template
1220
1197
@@ -1227,7 +1204,7 @@ But if you pass extra ones, they will be added to the URI as a query string::
1227
1204
$this->get('router')->generate('blog', array('page' => 2, 'category' => 'Symfony'));
1228
1205
// /blog/2?category=Symfony
1229
1206
1230
- Generating URLs from a template
1207
+ Generating URLs from a Template
1231
1208
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1232
1209
1233
1210
The most common place to generate a URL is from within a template when linking
@@ -1250,7 +1227,20 @@ a template helper function:
1250
1227
Read this blog post.
1251
1228
</a>
1252
1229
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->getgenerateUrl('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:
1254
1244
1255
1245
.. configuration-block ::
1256
1246
@@ -1268,6 +1258,14 @@ Absolute URLs can also be generated.
1268
1258
Read this blog post.
1269
1259
</a>
1270
1260
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
+
1271
1269
Summary
1272
1270
-------
1273
1271
0 commit comments