From 4187c51b5a3eb26a3731c15543c551891eaa49f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Tue, 3 Dec 2013 12:32:33 +0100 Subject: [PATCH] fixes #3267 Make sure we use camelCase for action arguments --- book/controller.rst | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/book/controller.rst b/book/controller.rst index 19fe515c5af..432ebf560ca 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -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 @@ -248,7 +248,7 @@ example: xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - + AcmeHelloBundle:Hello:index green @@ -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. @@ -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) { // ... } @@ -295,7 +295,7 @@ 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) { // ... } @@ -303,17 +303,17 @@ the following guidelines in mind while you develop. 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) { // ... }