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

Commita18e5cc

Browse files
committed
Clarify that route defaults don't need a placeholder
1 parent17addb1 commita18e5cc

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

‎book/routing.rst‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,10 @@ see :ref:`route-parameters-controller-arguments`.
955955
You can also use a special ``$_route`` variable, which is set to the
956956
name of the route that was matched.
957957

958+
You can even add extra information to your route definition and access it
959+
within your controller. For more information on this topic,
960+
see:doc:`/cookbook/routing/extra_information`.
961+
958962
..index::
959963
single: Routing; Importing routing resources
960964

‎cookbook/map.rst.inc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
* :doc:`/cookbook/routing/service_container_parameters`
129129
* :doc:`/cookbook/routing/custom_route_loader`
130130
* :doc:`/cookbook/routing/redirect_trailing_slash`
131+
* :doc:`/cookbook/routing/extra_information`
131132

132133
* :doc:`/cookbook/security/index`
133134

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
..index::
2+
single: Routing; Extra Information
3+
4+
How to Pass Extra Information from a Route to a Controller
5+
==========================================================
6+
7+
Parameters inside the ``defaults`` collection don't necessarily have to
8+
match a placeholder in the route ``path``. In fact, you can use the
9+
``defaults`` array to specify extra parameters that will then be accessible as
10+
arguments to your controller:
11+
12+
..configuration-block::
13+
14+
..code-block::yaml
15+
16+
# app/config/routing.yml
17+
blog:
18+
path:/blog/{page}
19+
defaults:
20+
_controller:AcmeBlogBundle:Blog:index
21+
page:1
22+
title:"Hello world!"
23+
24+
..code-block::xml
25+
26+
<!-- app/config/routing.xml-->
27+
<?xml version="1.0" encoding="UTF-8" ?>
28+
<routesxmlns="http://symfony.com/schema/routing"
29+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
30+
xsi:schemaLocation="http://symfony.com/schema/routing
31+
http://symfony.com/schema/routing/routing-1.0.xsd">
32+
33+
<routeid="blog"path="/blog/{page}">
34+
<defaultkey="_controller">AcmeBlogBundle:Blog:index</default>
35+
<defaultkey="page">1</default>
36+
<defaultkey="title">Hello world!</default>
37+
</route>
38+
</routes>
39+
40+
..code-block::php
41+
42+
// app/config/routing.php
43+
use Symfony\Component\Routing\RouteCollection;
44+
use Symfony\Component\Routing\Route;
45+
46+
$collection = new RouteCollection();
47+
$collection->add('blog', new Route('/blog/{page}', array(
48+
'_controller' => 'AcmeBlogBundle:Blog:index',
49+
'page' => 1,
50+
'title' => 'Hello world!',
51+
)));
52+
53+
return $collection;
54+
55+
Now, you can access this extra parameter in your controller::
56+
57+
public function indexAction($page, $title)
58+
{
59+
// ...
60+
}
61+
62+
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.

‎cookbook/routing/index.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ Routing
1111
service_container_parameters
1212
custom_route_loader
1313
redirect_trailing_slash
14+
extra_information

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp