File tree Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -1173,10 +1173,20 @@ route. With this information, any URL can easily be generated::
1173
1173
you can use the ``router `` service's
1174
1174
:method: `Symfony\\ Component\\ Routing\\ Router::generate ` method::
1175
1175
1176
- $url = $this->get('router')->generate(
1177
- 'blog_show',
1178
- array('slug' => 'my-blog-post')
1179
- );
1176
+ use Symfony\Component\DependencyInjection\ContainerAware;
1177
+
1178
+ class MainController extends ContainerAware
1179
+ {
1180
+ public function showAction($slug)
1181
+ {
1182
+ // ...
1183
+
1184
+ $url = $this->container->get('router')->generate(
1185
+ 'blog_show',
1186
+ array('slug' => 'my-blog-post')
1187
+ );
1188
+ }
1189
+ }
1180
1190
1181
1191
In an upcoming section, you'll learn how to generate URLs from inside templates.
1182
1192
@@ -1266,7 +1276,8 @@ From a template, it looks like this:
1266
1276
The host that's used when generating an absolute URL is automatically
1267
1277
detected using the current ``Request `` object. When generating absolute
1268
1278
URLs from outside the web context (for instance in a console command) this
1269
- won't work. See :doc: `/cookbook/console/sending_emails ` for details.
1279
+ doesn't work. See :doc: `/cookbook/console/sending_emails ` to learn how to
1280
+ solve this problem.
1270
1281
1271
1282
Summary
1272
1283
-------
You can’t perform that action at this time.
0 commit comments