@@ -91,10 +91,9 @@ or a ``Closure``), in Symfony, a controller is usually a single method inside
9191a controller object. Controllers are also called *actions *.
9292
9393.. code-block :: php
94- :linenos:
9594
96- // src/Acme/HelloBundle /Controller/HelloController.php
97- namespace Acme\HelloBundle \Controller;
95+ // src/AppBundle /Controller/HelloController.php
96+ namespace AppBundle \Controller;
9897
9998 use Symfony\Component\HttpFoundation\Response;
10099
@@ -151,7 +150,7 @@ to the controller:
151150 # app/config/routing.yml
152151 hello :
153152 path : /hello/{name}
154- defaults : { _controller: AcmeHelloBundle :Hello:index }
153+ defaults : { _controller: AppBundle :Hello:index }
155154
156155 .. code-block :: xml
157156
@@ -163,7 +162,7 @@ to the controller:
163162 http://symfony.com/schema/routing/routing-1.0.xsd" >
164163
165164 <route id =" hello" path =" /hello/{name}" >
166- <default key =" _controller" >AcmeHelloBundle :Hello:index</default >
165+ <default key =" _controller" >AppBundle :Hello:index</default >
167166 </route >
168167 </routes >
169168
@@ -175,7 +174,7 @@ to the controller:
175174
176175 $collection = new RouteCollection();
177176 $collection->add('hello', new Route('/hello/{name}', array(
178- '_controller' => 'AcmeHelloBundle :Hello:index',
177+ '_controller' => 'AppBundle :Hello:index',
179178 )));
180179
181180 return $collection;
@@ -184,10 +183,10 @@ Going to ``/hello/ryan`` now executes the ``HelloController::indexAction()``
184183controller and passes in ``ryan `` for the ``$name `` variable. Creating a
185184"page" means simply creating a controller method and associated route.
186185
187- Notice the syntax used to refer to the controller: ``AcmeHelloBundle :Hello:index ``.
186+ Notice the syntax used to refer to the controller: ``AppBundle :Hello:index ``.
188187Symfony uses a flexible string notation to refer to different controllers.
189188This is the most common syntax and tells Symfony to look for a controller
190- class called ``HelloController `` inside a bundle named ``AcmeHelloBundle ``. The
189+ class called ``HelloController `` inside a bundle named ``AppBundle ``. The
191190method ``indexAction() `` is then executed.
192191
193192For more details on the string format used to reference different controllers,
@@ -212,13 +211,13 @@ see :ref:`controller-string-syntax`.
212211Route Parameters as Controller Arguments
213212~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
214213
215- You already know that the ``_controller `` parameter ``AcmeHelloBundle :Hello:index ``
214+ You already know that the ``_controller `` parameter ``AppBundle :Hello:index ``
216215refers to a ``HelloController::indexAction() `` method that lives inside the
217- ``AcmeHelloBundle `` bundle. What's more interesting is the arguments that are
218- passed to that method::
216+ ``AppBundle `` bundle. What's more interesting is the arguments that are passed
217+ to that method::
219218
220- // src/Acme/HelloBundle /Controller/HelloController.php
221- namespace Acme\HelloBundle \Controller;
219+ // src/AppBundle /Controller/HelloController.php
220+ namespace AppBundle \Controller;
222221
223222 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
224223
@@ -243,7 +242,7 @@ example:
243242 # app/config/routing.yml
244243 hello :
245244 path : /hello/{firstName}/{lastName}
246- defaults : { _controller: AcmeHelloBundle :Hello:index, color: green }
245+ defaults : { _controller: AppBundle :Hello:index, color: green }
247246
248247 .. code-block :: xml
249248
@@ -255,7 +254,7 @@ example:
255254 http://symfony.com/schema/routing/routing-1.0.xsd" >
256255
257256 <route id =" hello" path =" /hello/{firstName}/{lastName}" >
258- <default key =" _controller" >AcmeHelloBundle :Hello:index</default >
257+ <default key =" _controller" >AppBundle :Hello:index</default >
259258 <default key =" color" >green</default >
260259 </route >
261260 </routes >
@@ -268,7 +267,7 @@ example:
268267
269268 $collection = new RouteCollection();
270269 $collection->add('hello', new Route('/hello/{firstName}/{lastName}', array(
271- '_controller' => 'AcmeHelloBundle :Hello:index',
270+ '_controller' => 'AppBundle :Hello:index',
272271 'color' => 'green',
273272 )));
274273
@@ -377,8 +376,8 @@ you can take advantage of several helper methods.
377376Add the ``use `` statement atop the ``Controller `` class and then modify the
378377``HelloController `` to extend it::
379378
380- // src/Acme/HelloBundle /Controller/HelloController.php
381- namespace Acme\HelloBundle \Controller;
379+ // src/AppBundle /Controller/HelloController.php
380+ namespace AppBundle \Controller;
382381
383382 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
384383 use Symfony\Component\HttpFoundation\Response;
@@ -472,7 +471,7 @@ object that's returned from that controller::
472471
473472 public function indexAction($name)
474473 {
475- $response = $this->forward('AcmeHelloBundle:Hello :fancy', array(
474+ $response = $this->forward('AppBundle:Something :fancy', array(
476475 'name' => $name,
477476 'color' => 'green',
478477 ));
@@ -484,22 +483,22 @@ object that's returned from that controller::
484483
485484Notice that the ``forward() `` method uses the same string representation of
486485the controller used in the routing configuration. In this case, the target
487- controller class will be ``HelloController `` inside some `` AcmeHelloBundle ``.
488- The array passed to the method becomes the arguments on the resulting controller.
489- This same interface is used when embedding controllers into templates (see
490- :ref: `templating-embedding-controller `). The target controller method should
491- look something like the following::
486+ controller class will be ``SomethingController::fancyAction() `` inside the
487+ `` AppBundle ``. The array passed to the method becomes the arguments on the
488+ resulting controller. This same interface is used when embedding controllers
489+ into templates (see :ref: `templating-embedding-controller `). The target
490+ controller method should look something like the following::
492491
493492 public function fancyAction($name, $color)
494493 {
495494 // ... create and return a Response object
496495 }
497496
498- And just like when creating a controller for a route, the order of the arguments
499- to ``fancyAction `` doesn't matter. Symfony matches the index key names
500- (e.g. ``name ``) with the method argument names (e.g. ``$name ``). If you
501- change the order of the arguments, Symfony will still pass the correct
502- value to each variable.
497+ Just like when creating a controller for a route, the order of the arguments of
498+ ``fancyAction `` doesn't matter. Symfony matches the index key names (e.g.
499+ ``name ``) with the method argument names (e.g. ``$name ``). If you change the
500+ order of the arguments, Symfony will still pass the correct value to each
501+ variable.
503502
504503.. tip ::
505504
@@ -512,7 +511,7 @@ value to each variable.
512511 use Symfony\Component\HttpKernel\HttpKernelInterface;
513512
514513 $path = array(
515- '_controller' => 'AcmeHelloBundle:Hello :fancy',
514+ '_controller' => 'AppBundle:Something :fancy',
516515 'name' => $name,
517516 'color' => 'green',
518517 );
0 commit comments