Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit722e7f0

Browse files
committed
minor#6219 Point that route parameters are also Request attributes (sfdumi)
This PR was submitted for the 3.0 branch but it was merged into the 2.3 branch instead (closes#6219).Discussion----------Point that route parameters are also Request attributesPoint that route parameters are also Request attributesCommits-------08aae4e Point that route parameters are also Request attributes
2 parents037c7a5 +08aae4e commit722e7f0

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

‎cookbook/routing/extra_information.rst

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ How to Pass Extra Information from a Route to a Controller
77
Parameters inside the ``defaults`` collection don't necessarily have to
88
match a placeholder in the route ``path``. In fact, you can use the
99
``defaults`` array to specify extra parameters that will then be accessible as
10-
arguments to your controller:
10+
arguments to your controller, and as attributes of the ``Request`` object:
1111

1212
..configuration-block::
1313

@@ -52,12 +52,25 @@ arguments to your controller:
5252
5353
return $collection;
5454
55-
Now, you can access this extra parameter in your controller::
55+
Now, you can access this extra parameter in your controller, as an argument to the controller method::
5656

57+
use Symfony\Component\HttpFoundation\Request;
58+
5759
public function indexAction($page, $title)
5860
{
5961
// ...
6062
}
6163

64+
Alternately, the title could be accessed through the ``Request`` object::
65+
66+
use Symfony\Component\HttpFoundation\Request;
67+
68+
public function indexAction(Request $request, $page)
69+
{
70+
// ...
71+
$title = $request->attributes->get('title');
72+
// ...
73+
}
74+
6275
As you can see, the ``$title`` variable was never defined inside the route path,
63-
but you can still access its value from inside your controller.
76+
but you can still access its value from inside your controller, through the method's argument, or from the ``Request`` object's ``attributes`` bag.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp