File tree Expand file tree Collapse file tree 2 files changed +16
-12
lines changed Expand file tree Collapse file tree 2 files changed +16
-12
lines changed Original file line number Diff line number Diff line change @@ -134,8 +134,8 @@ variable exists and will be available in your form themes::
134
134
the ``KernelTestCase `` instead and use the ``form.factory `` service to
135
135
create the form.
136
136
137
- Testings Types Registered as Services
138
- -------------------------------------
137
+ Testing Types Registered as Services
138
+ ------------------------------------
139
139
140
140
Your form may be used as a service, as it depends on other services (e.g. the
141
141
Doctrine entity manager). In these cases, using the above code won't work, as
Original file line number Diff line number Diff line change @@ -120,21 +120,25 @@ inside your controller::
120
120
121
121
// src/Controller/ProductController.php
122
122
use App\Service\MessageGenerator;
123
+ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
123
124
use Symfony\Component\HttpFoundation\Response;
124
125
use Symfony\Component\Routing\Annotation\Route;
125
126
126
- /**
127
- * @Route("/products/new")
128
- */
129
- public function new(MessageGenerator $messageGenerator): Response
127
+ class ProductController extends AbstractController
130
128
{
131
- // thanks to the type-hint, the container will instantiate a
132
- // new MessageGenerator and pass it to you!
133
- // ...
129
+ /**
130
+ * @Route("/products/new")
131
+ */
132
+ public function new(MessageGenerator $messageGenerator): Response
133
+ {
134
+ // thanks to the type-hint, the container will instantiate a
135
+ // new MessageGenerator and pass it to you!
136
+ // ...
134
137
135
- $message = $messageGenerator->getHappyMessage();
136
- $this->addFlash('success', $message);
137
- // ...
138
+ $message = $messageGenerator->getHappyMessage();
139
+ $this->addFlash('success', $message);
140
+ // ...
141
+ }
138
142
}
139
143
140
144
When you ask for the ``MessageGenerator `` service, the container constructs a new
You can’t perform that action at this time.
0 commit comments