Skip to content

Commit f397b10

Browse files
committed
minor #19822 Upload Files: Removing getParameter() (ThomasLandauer)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- Upload Files: Removing `getParameter()` Page: https://symfony.com/doc/5.x/controller/upload_file.html Wasn't `getParameter()` discouraged somehow? If yes, I should probably add `bind:` to the `config/services.yaml` code block, right? Commits ------- 2c16e40 Upload Files: Removing `getParameter()`
2 parents 7a2c7a9 + 2c16e40 commit f397b10

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

controller/upload_file.rst

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Finally, you need to update the code of the controller that handles the form::
134134
/**
135135
* @Route("/product/new", name="app_product_new")
136136
*/
137-
public function new(Request $request, SluggerInterface $slugger): Response
137+
public function new(Request $request, SluggerInterface $slugger, string $brochuresDirectory): Response
138138
{
139139
$product = new Product();
140140
$form = $this->createForm(ProductType::class, $product);
@@ -154,10 +154,7 @@ Finally, you need to update the code of the controller that handles the form::
154154

155155
// Move the file to the directory where brochures are stored
156156
try {
157-
$brochureFile->move(
158-
$this->getParameter('brochures_directory'),
159-
$newFilename
160-
);
157+
$brochureFile->move($brochuresDirectory, $newFilename);
161158
} catch (FileException $e) {
162159
// ... handle exception if something happens during file upload
163160
}
@@ -223,7 +220,7 @@ You can use the following code to link to the PDF brochure of a product:
223220
// ...
224221

225222
$product->setBrochureFilename(
226-
new File($this->getParameter('brochures_directory').'/'.$product->getBrochureFilename())
223+
new File($brochuresDirectory.DIRECTORY_SEPARATOR.$product->getBrochureFilename())
227224
);
228225

229226
Creating an Uploader Service

0 commit comments

Comments
 (0)