From da8b46f7a2fd2e8f599b2e945a885c964920bed7 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Sat, 29 Mar 2014 11:31:59 +0100 Subject: [PATCH 1/4] [book] [routing] used the American term "bidirectional" instead of the British bi-directional --- book/routing.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/book/routing.rst b/book/routing.rst index a6a1504c00a..a8a2974dcb5 100644 --- a/book/routing.rst +++ b/book/routing.rst @@ -1134,10 +1134,10 @@ Generating URLs --------------- The routing system should also be used to generate URLs. In reality, routing -is a bi-directional system: mapping the URL to a controller+parameters and +is a bidirectional system: mapping the URL to a controller+parameters and a route+parameters back to a URL. The :method:`Symfony\\Component\\Routing\\Router::match` and -:method:`Symfony\\Component\\Routing\\Router::generate` methods form this bi-directional +:method:`Symfony\\Component\\Routing\\Router::generate` methods form this bidirectional system. Take the ``blog_show`` example route from earlier:: $params = $this->get('router')->match('/blog/my-blog-post'); @@ -1272,7 +1272,7 @@ Summary Routing is a system for mapping the URL of incoming requests to the controller function that should be called to process the request. It both allows you to specify beautiful URLs and keeps the functionality of your application -decoupled from those URLs. Routing is a two-way mechanism, meaning that it +decoupled from those URLs. Routing is a bidirectional mechanism, meaning that it should also be used to generate URLs. Learn more from the Cookbook From 355cd5b9729fecc39f34f5547065aa90bcbc9ed7 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Sat, 29 Mar 2014 11:36:26 +0100 Subject: [PATCH 2/4] [book] [routing] reworded the note about generating URLs in console --- book/routing.rst | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/book/routing.rst b/book/routing.rst index a8a2974dcb5..9441a2e212e 100644 --- a/book/routing.rst +++ b/book/routing.rst @@ -1260,11 +1260,10 @@ From a template, it looks like this: .. note:: - The host that's used when generating an absolute URL is the host of - the current ``Request`` object. This is detected automatically. But if - you generate absolute URLs for scripts run from the command line, this - won't work. But don't worry! Just see :doc:`/cookbook/console/sending_emails` - for details. + The host that's used when generating an absolute URL is automatically + detected using the current ``Request`` object. When generating absolute + URLs from outside the web context (for instance in a console command) this + won't work. See :doc:`/cookbook/console/sending_emails` for details. Summary ------- From 26f9e3bd9eab888f0cc148a62a85c06a265e0e53 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Sat, 29 Mar 2014 11:40:11 +0100 Subject: [PATCH 3/4] [book] [routing] fixed a note that wasn't properly updated Previously, the code used the generate() method of the service and the note explained the generateUrl() method of the base controller. Then, the example was updated to use the generateUrl(), but the note kept explaining the generateUrl(). This change is just about explaining in the note the alterantive generate() method of the service. --- book/routing.rst | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/book/routing.rst b/book/routing.rst index 9441a2e212e..9d06e2ad906 100644 --- a/book/routing.rst +++ b/book/routing.rst @@ -1168,12 +1168,15 @@ route. With this information, any URL can easily be generated:: .. note:: - In controllers that extend Symfony's base + In controllers that don't extend Symfony's base :class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller`, - you can use the - :method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::generateUrl` - method, which calls the router service's - :method:`Symfony\\Component\\Routing\\Router::generate` method. + you can use the ``router`` service's + :method:`Symfony\\Component\\Routing\\Router::generate` method:: + + $url = $this->get('router')->generate( + 'blog_show', + array('slug' => 'my-blog-post') + ); In an upcoming section, you'll learn how to generate URLs from inside templates. From 7500435f97605836e63e3788c42f423766a0e929 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Sun, 30 Mar 2014 10:48:42 +0200 Subject: [PATCH 4/4] [book] [routing] minor rewording and fixed some sample code --- book/routing.rst | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/book/routing.rst b/book/routing.rst index 9d06e2ad906..623411d7827 100644 --- a/book/routing.rst +++ b/book/routing.rst @@ -1173,10 +1173,20 @@ route. With this information, any URL can easily be generated:: you can use the ``router`` service's :method:`Symfony\\Component\\Routing\\Router::generate` method:: - $url = $this->get('router')->generate( - 'blog_show', - array('slug' => 'my-blog-post') - ); + use Symfony\Component\DependencyInjection\ContainerAware; + + class MainController extends ContainerAware + { + public function showAction($slug) + { + // ... + + $url = $this->container->get('router')->generate( + 'blog_show', + array('slug' => 'my-blog-post') + ); + } + } In an upcoming section, you'll learn how to generate URLs from inside templates. @@ -1266,7 +1276,8 @@ From a template, it looks like this: The host that's used when generating an absolute URL is automatically detected using the current ``Request`` object. When generating absolute URLs from outside the web context (for instance in a console command) this - won't work. See :doc:`/cookbook/console/sending_emails` for details. + doesn't work. See :doc:`/cookbook/console/sending_emails` to learn how to + solve this problem. Summary -------