-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
da8b46f
[book] [routing] used the American term "bidirectional"
javiereguiluz 355cd5b
[book] [routing] reworded the note about generating URLs in console
javiereguiluz 26f9e3b
[book] [routing] fixed a note that wasn't properly updated
javiereguiluz 7500435
[book] [routing] minor rewording and fixed some sample code
javiereguiluz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,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. | ||
|
||
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [...] this doesn't work. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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'sController
if your controller doesn't extend it?