@@ -120,6 +120,7 @@ Finally, you need to update the code of the controller that handles the form::
120120 use App\Entity\Product;
121121 use App\Form\ProductType;
122122 use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
123+ use Symfony\Component\DependencyInjection\Attribute\Autowire;
123124 use Symfony\Component\HttpFoundation\File\Exception\FileException;
124125 use Symfony\Component\HttpFoundation\File\UploadedFile;
125126 use Symfony\Component\HttpFoundation\Request;
@@ -130,7 +131,11 @@ Finally, you need to update the code of the controller that handles the form::
130131 class ProductController extends AbstractController
131132 {
132133 #[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
134139 {
135140 $product = new Product();
136141 $form = $this->createForm(ProductType::class, $product);
@@ -171,18 +176,6 @@ Finally, you need to update the code of the controller that handles the form::
171176 }
172177 }
173178
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-
186179There are some important things to consider in the code of the above controller:
187180
188181#. In Symfony applications, uploaded files are objects of the
0 commit comments