Permalink
Browse files

minor #3736 [book] Misc. routing fixes (javiereguiluz)

This PR was merged into the 2.3 branch.

Discussion
----------

[book] Misc. routing fixes

| Q             | A
| ------------- | ---
| Doc fix?      | yes
| New docs?     | no
| Applies to    | 2.3+
| Fixed tickets | -

Commits
-------

7500435 [book] [routing] minor rewording and fixed some sample code
26f9e3b [book] [routing] fixed a note that wasn't properly updated
355cd5b [book] [routing] reworded the note about generating URLs in console
da8b46f [book] [routing] used the American term "bidirectional" instead of the British bi-directional
  • Loading branch information...
weaverryan committed Apr 2, 2014
2 parents f149dcf + 7500435 commit 54d6a9e738f99db87ff7c20cc6b394de11641155
Showing with 26 additions and 13 deletions.
  1. +26 −13 book/routing.rst
View
@@ -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');
@@ -1168,12 +1168,25 @@ 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::
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.
@@ -1262,19 +1275,19 @@ to ``generateUrl()``:
.. 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
doesn't work. See :doc:`/cookbook/console/sending_emails` to learn how to
solve this problem.
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

0 comments on commit 54d6a9e

Please sign in to comment.