Skip to content

Commit 9d6e1b5

Browse files
committed
Merge pull request #3268 from greg0ire/argument_naming_consistency
fixes #3267
2 parents b2d120c + 4187c51 commit 9d6e1b5

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

book/controller.rst

+11-11
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ example:
236236
237237
# app/config/routing.yml
238238
hello:
239-
path: /hello/{first_name}/{last_name}
239+
path: /hello/{firstName}/{lastName}
240240
defaults: { _controller: AcmeHelloBundle:Hello:index, color: green }
241241
242242
.. code-block:: xml
@@ -248,7 +248,7 @@ example:
248248
xsi:schemaLocation="http://symfony.com/schema/routing
249249
http://symfony.com/schema/routing/routing-1.0.xsd">
250250
251-
<route id="hello" path="/hello/{first_name}/{last_name}">
251+
<route id="hello" path="/hello/{firstName}/{lastName}">
252252
<default key="_controller">AcmeHelloBundle:Hello:index</default>
253253
<default key="color">green</default>
254254
</route>
@@ -257,19 +257,19 @@ example:
257257
.. code-block:: php
258258
259259
// app/config/routing.php
260-
$collection->add('hello', new Route('/hello/{first_name}/{last_name}', array(
260+
$collection->add('hello', new Route('/hello/{firstName}/{lastName}', array(
261261
'_controller' => 'AcmeHelloBundle:Hello:index',
262262
'color' => 'green',
263263
)));
264264
265265
The controller for this can take several arguments::
266266

267-
public function indexAction($first_name, $last_name, $color)
267+
public function indexAction($firstName, $lastName, $color)
268268
{
269269
// ...
270270
}
271271

272-
Notice that both placeholder variables (``{first_name}``, ``{last_name}``)
272+
Notice that both placeholder variables (``{firstName}``, ``{lastName}``)
273273
as well as the default ``color`` variable are available as arguments in the
274274
controller. When a route is matched, the placeholder variables are merged
275275
with the ``defaults`` to make one array that's available to your controller.
@@ -281,11 +281,11 @@ the following guidelines in mind while you develop.
281281

282282
Symfony is able to match the parameter names from the route to the variable
283283
names in the controller method's signature. In other words, it realizes that
284-
the ``{last_name}`` parameter matches up with the ``$last_name`` argument.
284+
the ``{lastName}`` parameter matches up with the ``$lastName`` argument.
285285
The arguments of the controller could be totally reordered and still work
286286
perfectly::
287287

288-
public function indexAction($last_name, $color, $first_name)
288+
public function indexAction($lastName, $color, $firstName)
289289
{
290290
// ...
291291
}
@@ -295,25 +295,25 @@ the following guidelines in mind while you develop.
295295
The following would throw a ``RuntimeException`` because there is no ``foo``
296296
parameter defined in the route::
297297

298-
public function indexAction($first_name, $last_name, $color, $foo)
298+
public function indexAction($firstName, $lastName, $color, $foo)
299299
{
300300
// ...
301301
}
302302

303303
Making the argument optional, however, is perfectly ok. The following
304304
example would not throw an exception::
305305

306-
public function indexAction($first_name, $last_name, $color, $foo = 'bar')
306+
public function indexAction($firstName, $lastName, $color, $foo = 'bar')
307307
{
308308
// ...
309309
}
310310

311311
* **Not all routing parameters need to be arguments on your controller**
312312

313-
If, for example, the ``last_name`` weren't important for your controller,
313+
If, for example, the ``lastName`` weren't important for your controller,
314314
you could omit it entirely::
315315

316-
public function indexAction($first_name, $color)
316+
public function indexAction($firstName, $color)
317317
{
318318
// ...
319319
}

0 commit comments

Comments
 (0)