Skip to content

fixes #3267 #3268

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

Merged
merged 1 commit into from
Dec 3, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions book/controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ example:

# app/config/routing.yml
hello:
path: /hello/{first_name}/{last_name}
path: /hello/{firstName}/{lastName}
defaults: { _controller: AcmeHelloBundle:Hello:index, color: green }

.. code-block:: xml
Expand All @@ -248,7 +248,7 @@ example:
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="hello" path="/hello/{first_name}/{last_name}">
<route id="hello" path="/hello/{firstName}/{lastName}">
<default key="_controller">AcmeHelloBundle:Hello:index</default>
<default key="color">green</default>
</route>
Expand All @@ -257,19 +257,19 @@ example:
.. code-block:: php

// app/config/routing.php
$collection->add('hello', new Route('/hello/{first_name}/{last_name}', array(
$collection->add('hello', new Route('/hello/{firstName}/{lastName}', array(
'_controller' => 'AcmeHelloBundle:Hello:index',
'color' => 'green',
)));

The controller for this can take several arguments::

public function indexAction($first_name, $last_name, $color)
public function indexAction($firstName, $lastName, $color)
{
// ...
}

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

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

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

public function indexAction($first_name, $last_name, $color, $foo)
public function indexAction($firstName, $lastName, $color, $foo)
{
// ...
}

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

public function indexAction($first_name, $last_name, $color, $foo = 'bar')
public function indexAction($firstName, $lastName, $color, $foo = 'bar')
{
// ...
}

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

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

public function indexAction($first_name, $color)
public function indexAction($firstName, $color)
{
// ...
}
Expand Down