Skip to content

Adding showing the base controller's urlGenerate method and a related note #2261

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

Merged
merged 2 commits into from
Feb 25, 2013
Merged
Changes from all 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
15 changes: 12 additions & 3 deletions book/routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1067,13 +1067,13 @@ a route+parameters back to a URL. The
:method:`Symfony\\Component\\Routing\\Router::generate` methods form this bi-directional
system. Take the ``blog_show`` example route from earlier::

$params = $router->match('/blog/my-blog-post');
$params = $this->get('router')->match('/blog/my-blog-post');
// array(
// 'slug' => 'my-blog-post',
// '_controller' => 'AcmeBlogBundle:Blog:show',
// )

$uri = $router->generate('blog_show', array('slug' => 'my-blog-post'));
$uri = $this->get('router')->generate('blog_show', array('slug' => 'my-blog-post'));
// /blog/my-blog-post

To generate a URL, you need to specify the name of the route (e.g. ``blog_show``)
Expand All @@ -1086,13 +1086,22 @@ that route. With this information, any URL can easily be generated::
{
// ...

$url = $this->get('router')->generate(
$url = $this->generateUrl(
'blog_show',
array('slug' => 'my-blog-post')
);
}
}

.. note::

In controllers extending from the base
:class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller`,
you can use the
:method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::generateUrl`
method which call's the router service's
:method:`Symfony\\Component\\Routing\\Router::generate` method.

In an upcoming section, you'll learn how to generate URLs from inside templates.

.. tip::
Expand Down