@@ -10,7 +10,7 @@ class::
10
10
11
11
class LeapYearController
12
12
{
13
- public function indexAction ($request)
13
+ public function index ($request)
14
14
{
15
15
if (is_leap_year($request->attributes->get('year'))) {
16
16
return new Response('Yep, this is a leap year!');
@@ -99,39 +99,39 @@ following interface::
99
99
public function getArguments(Request $request, $controller);
100
100
}
101
101
102
- The ``indexAction () `` method needs the Request object as an argument.
102
+ The ``index () `` method needs the Request object as an argument.
103
103
``getArguments() `` knows when to inject it properly if it is type-hinted
104
104
correctly::
105
105
106
- public function indexAction (Request $request)
106
+ public function index (Request $request)
107
107
108
108
// won't work
109
- public function indexAction ($request)
109
+ public function index ($request)
110
110
111
111
More interesting, ``getArguments() `` is also able to inject any Request
112
112
attribute; the argument just needs to have the same name as the corresponding
113
113
attribute::
114
114
115
- public function indexAction ($year)
115
+ public function index ($year)
116
116
117
117
You can also inject the Request and some attributes at the same time (as the
118
118
matching is done on the argument name or a type hint, the arguments order does
119
119
not matter)::
120
120
121
- public function indexAction (Request $request, $year)
121
+ public function index (Request $request, $year)
122
122
123
- public function indexAction ($year, Request $request)
123
+ public function index ($year, Request $request)
124
124
125
125
Finally, you can also define default values for any argument that matches an
126
126
optional attribute of the Request::
127
127
128
- public function indexAction ($year = 2012)
128
+ public function index ($year = 2012)
129
129
130
130
Let's just inject the ``$year `` request attribute for our controller::
131
131
132
132
class LeapYearController
133
133
{
134
- public function indexAction ($year)
134
+ public function index ($year)
135
135
{
136
136
if (is_leap_year($year)) {
137
137
return new Response('Yep, this is a leap year!');
0 commit comments