Skip to content

Commit 6ef10db

Browse files
committed
Moving forwarding section all the way to the bottom
I could find very little real use-cases for this.
1 parent 0754efc commit 6ef10db

File tree

1 file changed

+43
-43
lines changed

1 file changed

+43
-43
lines changed

book/controller.rst

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -515,49 +515,6 @@ The Symfony templating engine is explained in great detail in the
515515
// puts the content into a Response object for convenience
516516
$content = $templating->renderResponse('Hello/index.html.twig', array('name' => $name));
517517

518-
.. index::
519-
single: Controller; Forwarding
520-
521-
Forwarding
522-
~~~~~~~~~~
523-
524-
You can also forward to another controller internally with the
525-
:method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::forward`
526-
method. Instead of redirecting the user's browser, it makes an internal sub-request,
527-
and calls the controller. The ``forward()`` method returns the ``Response``
528-
object that's returned from *that* controller::
529-
530-
public function indexAction($name)
531-
{
532-
$response = $this->forward('AppBundle:Something:fancy', array(
533-
'name' => $name,
534-
'color' => 'green',
535-
));
536-
537-
// ... further modify the response or return it directly
538-
539-
return $response;
540-
}
541-
542-
Notice that the ``forward()`` method uses a special string representation
543-
of the controller (see :ref:`controller-string-syntax`). In this case, the
544-
target controller function will be ``SomethingController::fancyAction()``
545-
inside the ``AppBundle``. The array passed to the method becomes the arguments
546-
on the resulting controller. This same idea is used when embedding controllers
547-
into templates (see :ref:`templating-embedding-controller`). The target
548-
controller method would look something like this::
549-
550-
public function fancyAction($name, $color)
551-
{
552-
// ... create and return a Response object
553-
}
554-
555-
Just like when creating a controller for a route, the order of the arguments of
556-
``fancyAction`` doesn't matter. Symfony matches the index key names (e.g.
557-
``name``) with the method argument names (e.g. ``$name``). If you change the
558-
order of the arguments, Symfony will still pass the correct value to each
559-
variable.
560-
561518
.. index::
562519
single: Controller; Accessing services
563520

@@ -808,6 +765,49 @@ and template are needed).
808765

809766
Use it! See :doc:`/cookbook/templating/render_without_controller`.
810767

768+
.. index::
769+
single: Controller; Forwarding
770+
771+
Forwarding to Another Controller
772+
--------------------------------
773+
774+
Though not very common, you can also forward to another controller internally
775+
with the :method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::forward`
776+
method. Instead of redirecting the user's browser, it makes an internal sub-request,
777+
and calls the controller. The ``forward()`` method returns the ``Response``
778+
object that's returned from *that* controller::
779+
780+
public function indexAction($name)
781+
{
782+
$response = $this->forward('AppBundle:Something:fancy', array(
783+
'name' => $name,
784+
'color' => 'green',
785+
));
786+
787+
// ... further modify the response or return it directly
788+
789+
return $response;
790+
}
791+
792+
Notice that the ``forward()`` method uses a special string representation
793+
of the controller (see :ref:`controller-string-syntax`). In this case, the
794+
target controller function will be ``SomethingController::fancyAction()``
795+
inside the ``AppBundle``. The array passed to the method becomes the arguments
796+
on the resulting controller. This same idea is used when embedding controllers
797+
into templates (see :ref:`templating-embedding-controller`). The target
798+
controller method would look something like this::
799+
800+
public function fancyAction($name, $color)
801+
{
802+
// ... create and return a Response object
803+
}
804+
805+
Just like when creating a controller for a route, the order of the arguments of
806+
``fancyAction`` doesn't matter. Symfony matches the index key names (e.g.
807+
``name``) with the method argument names (e.g. ``$name``). If you change the
808+
order of the arguments, Symfony will still pass the correct value to each
809+
variable.
810+
811811
Final Thoughts
812812
--------------
813813

0 commit comments

Comments
 (0)