Skip to content

[Upload files] parameter or bind? #20039

Closed
@Nayte91

Description

@Nayte91

Hello,

I was following the documentation here https://symfony.com/doc/current/controller/upload_file.html, everything was ok but I was stuck on this part :

Now, create the brochures_directory parameter that was used in the controller to specify the directory in which the brochures should be stored:

# config/services.yaml

# ...
parameters:
    brochures_directory: '%kernel.project_dir%/public/uploads/brochures'

When I was trying (I'm on a 7.1 project), on my own controller, I get an error:

Controller "App\Controller\news\NewsController::create" requires the "$bannersDirectory" argument that could not be resolved. Either the argument is nullable and no null value has been provided, no default value has been provided or there is a non-optional argument after this one.

So I changed a bit my services.yaml, removing this "parameters" part, and adding:

services:
    _defaults:
        autowire: true
        autoconfigure: true
        bind:
            $bannersDirectory: '%kernel.project_dir%/public/uploads/banners'

And it works!

So I was wondering, has the docs a flaw here? Or do I miss a point from newer SF version, about binding and parameters? That totally can be as I have troubles to understand this config/container part.

I can update the doc, but I need to know why my try didn't work, and what is ultimately the most elegant way to do :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    hasPRA Pull Request has already been submitted for this issue.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions