Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[book] Misc. routing fixes #3736

Merged
merged 4 commits into from
Apr 2, 2014
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions book/routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you call the get() method of FrameBundle's Controller if your controller doesn't extend it?

: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.

Expand Down Expand Up @@ -1260,19 +1263,18 @@ 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[...] this doesn't work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See [...] 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
Expand Down