@@ -91,10 +91,9 @@ or a ``Closure``), in Symfony, a controller is usually a single method inside
91
91
a controller object. Controllers are also called *actions *.
92
92
93
93
.. code-block :: php
94
- :linenos:
95
94
96
- // src/Acme/HelloBundle /Controller/HelloController.php
97
- namespace Acme\HelloBundle \Controller;
95
+ // src/AppBundle /Controller/HelloController.php
96
+ namespace AppBundle \Controller;
98
97
99
98
use Symfony\Component\HttpFoundation\Response;
100
99
@@ -151,7 +150,7 @@ to the controller:
151
150
# app/config/routing.yml
152
151
hello :
153
152
path : /hello/{name}
154
- defaults : { _controller: AcmeHelloBundle :Hello:index }
153
+ defaults : { _controller: AppBundle :Hello:index }
155
154
156
155
.. code-block :: xml
157
156
@@ -163,7 +162,7 @@ to the controller:
163
162
http://symfony.com/schema/routing/routing-1.0.xsd" >
164
163
165
164
<route id =" hello" path =" /hello/{name}" >
166
- <default key =" _controller" >AcmeHelloBundle :Hello:index</default >
165
+ <default key =" _controller" >AppBundle :Hello:index</default >
167
166
</route >
168
167
</routes >
169
168
@@ -175,7 +174,7 @@ to the controller:
175
174
176
175
$collection = new RouteCollection();
177
176
$collection->add('hello', new Route('/hello/{name}', array(
178
- '_controller' => 'AcmeHelloBundle :Hello:index',
177
+ '_controller' => 'AppBundle :Hello:index',
179
178
)));
180
179
181
180
return $collection;
@@ -184,10 +183,10 @@ Going to ``/hello/ryan`` now executes the ``HelloController::indexAction()``
184
183
controller and passes in ``ryan `` for the ``$name `` variable. Creating a
185
184
"page" means simply creating a controller method and associated route.
186
185
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 ``.
188
187
Symfony uses a flexible string notation to refer to different controllers.
189
188
This 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
191
190
method ``indexAction() `` is then executed.
192
191
193
192
For more details on the string format used to reference different controllers,
@@ -212,13 +211,13 @@ see :ref:`controller-string-syntax`.
212
211
Route Parameters as Controller Arguments
213
212
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
214
213
215
- You already know that the ``_controller `` parameter ``AcmeHelloBundle :Hello:index ``
214
+ You already know that the ``_controller `` parameter ``AppBundle :Hello:index ``
216
215
refers 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::
219
218
220
- // src/Acme/HelloBundle /Controller/HelloController.php
221
- namespace Acme\HelloBundle \Controller;
219
+ // src/AppBundle /Controller/HelloController.php
220
+ namespace AppBundle \Controller;
222
221
223
222
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
224
223
@@ -243,7 +242,7 @@ example:
243
242
# app/config/routing.yml
244
243
hello :
245
244
path : /hello/{firstName}/{lastName}
246
- defaults : { _controller: AcmeHelloBundle :Hello:index, color: green }
245
+ defaults : { _controller: AppBundle :Hello:index, color: green }
247
246
248
247
.. code-block :: xml
249
248
@@ -255,7 +254,7 @@ example:
255
254
http://symfony.com/schema/routing/routing-1.0.xsd" >
256
255
257
256
<route id =" hello" path =" /hello/{firstName}/{lastName}" >
258
- <default key =" _controller" >AcmeHelloBundle :Hello:index</default >
257
+ <default key =" _controller" >AppBundle :Hello:index</default >
259
258
<default key =" color" >green</default >
260
259
</route >
261
260
</routes >
@@ -268,7 +267,7 @@ example:
268
267
269
268
$collection = new RouteCollection();
270
269
$collection->add('hello', new Route('/hello/{firstName}/{lastName}', array(
271
- '_controller' => 'AcmeHelloBundle :Hello:index',
270
+ '_controller' => 'AppBundle :Hello:index',
272
271
'color' => 'green',
273
272
)));
274
273
@@ -377,8 +376,8 @@ you can take advantage of several helper methods.
377
376
Add the ``use `` statement atop the ``Controller `` class and then modify the
378
377
``HelloController `` to extend it::
379
378
380
- // src/Acme/HelloBundle /Controller/HelloController.php
381
- namespace Acme\HelloBundle \Controller;
379
+ // src/AppBundle /Controller/HelloController.php
380
+ namespace AppBundle \Controller;
382
381
383
382
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
384
383
use Symfony\Component\HttpFoundation\Response;
@@ -472,7 +471,7 @@ object that's returned from that controller::
472
471
473
472
public function indexAction($name)
474
473
{
475
- $response = $this->forward('AcmeHelloBundle:Hello :fancy', array(
474
+ $response = $this->forward('AppBundle:Something :fancy', array(
476
475
'name' => $name,
477
476
'color' => 'green',
478
477
));
@@ -484,22 +483,22 @@ object that's returned from that controller::
484
483
485
484
Notice that the ``forward() `` method uses the same string representation of
486
485
the 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::
492
491
493
492
public function fancyAction($name, $color)
494
493
{
495
494
// ... create and return a Response object
496
495
}
497
496
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.
503
502
504
503
.. tip ::
505
504
@@ -512,7 +511,7 @@ value to each variable.
512
511
use Symfony\Component\HttpKernel\HttpKernelInterface;
513
512
514
513
$path = array(
515
- '_controller' => 'AcmeHelloBundle:Hello :fancy',
514
+ '_controller' => 'AppBundle:Something :fancy',
516
515
'name' => $name,
517
516
'color' => 'green',
518
517
);
0 commit comments