3

I need to save a file in /web/import path and I am asking which is the best way to achieve this. I have a class defined in /Service/SyncController.php and it extends from Controller:

class SyncController extends Controller { ... } 

That class is defined as a service also:

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

Do I need to pass the argument "%kernel.root_dir%" in order to access web path as $this->webRoot = realpath($rootDir . '/../web') or I can do it from @service_container? Which is the right way to get the path to /web/import in order to save files in there?

ReynierPM
  • 17,594
  • 53
  • 193
  • 363
  • I think that `web` is not defined in Symfony so you may not be able to get its path. – A.L Jun 23 '15 at 15:02

1 Answers1

2

we use this configuration to do just this.

in parameters.yml

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

we split path from dir just for simplicity of reading.

in the controller:

$work_dir = $this->container->getParameter('upload_dir');
DevDonkey
  • 4,835
  • 2
  • 27
  • 41