@@ -120,6 +120,7 @@ Finally, you need to update the code of the controller that handles the form::
120
120
use App\Entity\Product;
121
121
use App\Form\ProductType;
122
122
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
123
+ use Symfony\Component\DependencyInjection\Attribute\Autowire;
123
124
use Symfony\Component\HttpFoundation\File\Exception\FileException;
124
125
use Symfony\Component\HttpFoundation\File\UploadedFile;
125
126
use Symfony\Component\HttpFoundation\Request;
@@ -130,7 +131,11 @@ Finally, you need to update the code of the controller that handles the form::
130
131
class ProductController extends AbstractController
131
132
{
132
133
#[Route('/product/new', name: 'app_product_new')]
133
- public function new(Request $request, SluggerInterface $slugger, string $brochuresDirectory): Response
134
+ public function new(
135
+ Request $request,
136
+ SluggerInterface $slugger,
137
+ #[Autowire('%kernel.project_dir%/public/uploads/brochures')] string $brochuresDirectory
138
+ ): Response
134
139
{
135
140
$product = new Product();
136
141
$form = $this->createForm(ProductType::class, $product);
@@ -171,18 +176,6 @@ Finally, you need to update the code of the controller that handles the form::
171
176
}
172
177
}
173
178
174
- Now, bind the ``$brochuresDirectory `` controller argument to its actual value
175
- using the service configuration:
176
-
177
- .. code-block :: yaml
178
-
179
- # config/services.yaml
180
- services :
181
- _defaults :
182
- # ...
183
- bind :
184
- string $brochuresDirectory : ' %kernel.project_dir%/public/uploads/brochures'
185
-
186
179
There are some important things to consider in the code of the above controller:
187
180
188
181
#. In Symfony applications, uploaded files are objects of the
0 commit comments