What is the best way to get the root app directory from inside the controller? Is it possible to get it outside of the controller?
Now I get it by passing it (from param
If you are using this path to access parts of the projects which are not code (for example an upload directory, or a SQLite database) then it might be better to turn the path into a parameter, like this:
parameters:
database_path: '%kernel.root_dir%/../var/sqlite3.db'
This parameter can be injected everywhere you need it, so you don't have to mess around with paths in your code any more. Also, the parameter can be overridden at deployment time. Finally, every maintaining programmer will have a better idea what you are using it for.
Update: Fixed kernel.root_dir constant usage.