Skip to content

Commit 2c16e40

Browse files
ThomasLandauerjaviereguiluz
authored andcommitted
Upload Files: Removing getParameter()
1 parent 7e54e23 commit 2c16e40

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)