Can I reach "/ web" path from container in Symfony2?

I need to save a file in a path /web/import

and I ask what is the best way for it. I have a class defined in /Service/SyncController.php

and it extends from Controller

:

class SyncController extends Controller { ... } 

      

This class is also defined as a service:

sync.service:
    class: PDI\PDOneBundle\Service\SyncController
    arguments: ["@service_container", "@doctrine.orm.entity_manager", "@request_stack", "%kernel.root_dir%"]

      

Do I need to pass an argument "%kernel.root_dir%"

to access the web path like $this->webRoot = realpath($rootDir . '/../web')

or can I do it with @service_container

? What is the correct way to get the path to /web/import

in order to save the files there?

+3


source to share


1 answer


we use this configuration to do this.

in parameters .yml

upload_path: "/images/uploads"
upload_dir: "%kernel.root_dir%/../web%upload_path%"

      



we are splitting the path from dir just for readability.

in the controller:

$work_dir = $this->container->getParameter('upload_dir');

      

+2


source







All Articles