Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get application root URL and Directory name in Symfony 2 application

Tags:

symfony

I want to know the root of the application both system eg. /var/www/app/ or /app/ for the purposes of file uploads. When I upload, I believe I need the "system" directory name, for use to links in web front end, I need the "relative" path. How do I get this information?

In a previous project, I defined constants in the app*.php files (front controller)

define('APP_ROOT', __DIR__);

Wonder if theres a better way?

like image 612
Jiew Meng Avatar asked May 07 '12 11:05

Jiew Meng


1 Answers

In any ContainerAware class you can get location of web directory by,

$this->container->get('kernel')->getRootdir().'/../web';
like image 78
Mun Mun Das Avatar answered Nov 08 '22 00:11

Mun Mun Das