Skip to content

Commit 55d376f

Browse files
committed
Reword code to use the Autowire attribute
1 parent e5e3c37 commit 55d376f

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

controller/upload_file.rst

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
186179
There 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

Comments
 (0)