@@ -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,17 +176,6 @@ Finally, you need to update the code of the controller that handles the form::
171
176
}
172
177
}
173
178
174
- Now, create the ``brochures_directory `` parameter that was used in the
175
- controller to specify the directory in which the brochures should be stored:
176
-
177
- .. code-block :: yaml
178
-
179
- # config/services.yaml
180
-
181
- # ...
182
- parameters :
183
- brochures_directory : ' %kernel.project_dir%/public/uploads/brochures'
184
-
185
179
There are some important things to consider in the code of the above controller:
186
180
187
181
#. In Symfony applications, uploaded files are objects of the
0 commit comments