@@ -1134,10 +1134,10 @@ Generating URLs
11341134---------------
11351135
11361136The routing system should also be used to generate URLs. In reality, routing
1137- is abi-directional system: mapping the URL to a controller+parameters and
1137+ is abidirectional system: mapping the URL to a controller+parameters and
11381138a route+parameters back to a URL. The
11391139:method: `Symfony\\ Component\\ Routing\\ Router::match ` and
1140- :method: `Symfony\\ Component\\ Routing\\ Router::generate ` methods form thisbi-directional
1140+ :method: `Symfony\\ Component\\ Routing\\ Router::generate ` methods form thisbidirectional
11411141system. Take the ``blog_show `` example route from earlier::
11421142
11431143 $params = $this->get('router')->match('/blog/my-blog-post');
@@ -1168,12 +1168,25 @@ route. With this information, any URL can easily be generated::
11681168
11691169..note ::
11701170
1171- In controllers that extend Symfony's base
1171+ In controllers thatdon't extend Symfony's base
11721172:class: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller `,
1173- you can use the
1174- :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::generateUrl `
1175- method, which calls the router service's
1176- :method: `Symfony\\ Component\\ Routing\\ Router::generate ` method.
1173+ you can use the ``router `` service's
1174+ :method: `Symfony\\ Component\\ Routing\\ Router::generate ` method::
1175+
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+ }
11771190
11781191In an upcoming section, you'll learn how to generate URLs from inside templates.
11791192
@@ -1262,19 +1275,19 @@ to ``generateUrl()``:
12621275
12631276..note ::
12641277
1265- The host that's used when generating an absolute URL isthe host of
1266- the current ``Request `` object.This is detected automatically. But if
1267- you generate absolute URLs forscripts run from the command line, this
1268- won 't work.But don't worry! Just see :doc: `/cookbook/console/sending_emails `
1269- for details .
1278+ The host that's used when generating an absolute URL isautomatically
1279+ detected using the current ``Request `` object.When generating absolute
1280+ URLs from outside the web context ( forinstance in a console command) this
1281+ doesn 't work.See :doc: `/cookbook/console/sending_emails ` to learn how to
1282+ solve this problem .
12701283
12711284Summary
12721285-------
12731286
12741287Routing is a system for mapping the URL of incoming requests to the controller
12751288function that should be called to process the request. It both allows you
12761289to specify beautiful URLs and keeps the functionality of your application
1277- decoupled from those URLs. Routing is atwo-way mechanism, meaning that it
1290+ decoupled from those URLs. Routing is abidirectional mechanism, meaning that it
12781291should also be used to generate URLs.
12791292
12801293Learn more from the Cookbook