0

In my project i have lot of different types of document of user to be uploaded. I am using local drive to save media and ony save the file. What it want is to define the uploaded directory in only configuration file (category wise) access it in controller and twig files. so that if i changed the media path later, i have to change it only once and should work everywhere?

I know lot bundle available for this, but i am not using any bundle I used doctrine to upload this media. More, later i also move this media to Amazon S3.

Muhammad Taqi
  • 5,356
  • 7
  • 36
  • 61

1 Answers1

1

You can do it directly in parameters.yml:

parameters:
    /.../
    media_directory: '%kernel.root_dir%/../web/uploads'

And you can have access in controller like all other parameters:

public function someAction() 
{
    $directory = $this->getParameter('media_directory');
}

EDIT

For twig, try like that:

<p>Media Directory: {{ media_directory }}</p>

Before, I think you have to declare twig global var in app/config/config.yml:

# Twig Configuration
twig:
    globals:
        media_directory: %media_directory%
scoolnico
  • 3,055
  • 14
  • 24