@@ -86,14 +86,14 @@ For more information on routing, see :doc:`/routing`.
86
86
single: Controller; Base controller class
87
87
88
88
.. _the-base-controller-class-services :
89
+ .. _the-base-controller-classes-services :
89
90
90
- The Base Controller Classes & Services
91
- --------------------------------------
91
+ The Base Controller Class & Services
92
+ ------------------------------------
92
93
93
- To make life nicer, Symfony comes with two optional base
94
- :class: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller ` and
94
+ To make life nicer, Symfony comes with an optional base controller class called
95
95
:class: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ AbstractController `.
96
- You can extend either to get access to some `helper methods `_.
96
+ You can extend it to get access to some `helper methods `_.
97
97
98
98
Add the ``use `` statement atop your controller class and then modify
99
99
``LuckyController `` to extend it:
@@ -103,35 +103,24 @@ Add the ``use`` statement atop your controller class and then modify
103
103
// src/Controller/LuckyController.php
104
104
namespace App\Controller;
105
105
106
- + use Symfony\Bundle\FrameworkBundle\Controller\Controller ;
106
+ + use Symfony\Bundle\FrameworkBundle\Controller\AbstractController ;
107
107
108
108
- class LuckyController
109
- + class LuckyController extends Controller
109
+ + class LuckyController extends AbstractController
110
110
{
111
111
// ...
112
112
}
113
113
114
114
That's it! You now have access to methods like :ref: `$this->render() <controller-rendering-templates >`
115
115
and many others that you'll learn about next.
116
116
117
- .. _controller-abstract-versus-controller :
118
-
119
- .. tip ::
120
-
121
- What's the difference between ``Controller `` or ``AbstractController ``? Not much:
122
- both are identical, except that ``AbstractController `` is more restrictive: it
123
- does not allow you to access services directly via ``$this->get() `` or
124
- ``$this->container->get() ``. This forces you to write more robust code to access
125
- services. But if you *do * need direct access to the container, using ``Controller ``
126
- is fine.
127
-
128
117
.. index ::
129
118
single: Controller; Redirecting
130
119
131
120
Generating URLs
132
121
~~~~~~~~~~~~~~~
133
122
134
- The :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller ::generateUrl `
123
+ The :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ ControllerTrait ::generateUrl `
135
124
method is just a helper method that generates the URL for a given route::
136
125
137
126
$url = $this->generateUrl('app_lucky_number', array('max' => 10));
@@ -650,7 +639,7 @@ contains the logic for that page. In Symfony, this is called a controller,
650
639
and it's a PHP function where you can do anything in order to return the
651
640
final ``Response `` object that will be returned to the user.
652
641
653
- To make life easier, you'll probably extend the base ``Controller `` class because
642
+ To make life easier, you'll probably extend the base ``AbstractController `` class because
654
643
this gives access to shortcut methods (like ``render() `` and ``redirectToRoute() ``).
655
644
656
645
In other articles, you'll learn how to use specific services from inside your controller
0 commit comments