0

How to get the Symfony public folder on commands.

On request to get the /var/www/myapp/web folder I can call:

$this->get('request')->getBasePath();

but how to get the public folder on a command and I don't want something hardcoded like %kernel.dir%/../web, because it should also work when the installation use public not web as folder or other custom folders.

Alexander Schranz
  • 2,154
  • 2
  • 25
  • 42
  • 1
    You could define your "web" folder as a variable in parameters.yml and read it from there if you want to have dynamic web folder... But %kernel.dir%/../web seems to be the best choice. – Stev Apr 08 '15 at 13:00
  • This answer looks also nice to find the /web folder: http://stackoverflow.com/a/27949505/4074148 (not tested) – Veve Apr 08 '15 at 13:03
  • but for this assetic bundle is needed dont want to make requirements only for finding the public folder. – Alexander Schranz Apr 08 '15 at 13:06

1 Answers1

1

There is no way to do that. The /web folder is referenced only in the Virtual Host web server (apache/nginx) directive. Symfony does not need to know that the /web folder is the one where the visitor lands. The app.php and app_dev.php do everything relatively.

Moreover, it "kinda" does not make much sense to have such requirement. If you're developing a command, you could add an optional Option to it. Something like "--webDir=web", where "web" is the default value. If the web server is configured otherwise, the command user will pass a different value like "--webDir=myWebDir", e.g.

P. R. Ribeiro
  • 2,999
  • 1
  • 19
  • 20
  • ok make sense that its not important for symfony to know the public folder, I looked at the `assetic bundle` and there it also needed to be configured where the public folder is thx for answering – Alexander Schranz Apr 08 '15 at 13:04