Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get application's root directory?

How do I get application's root directory within an action?

like image 880
Ree Avatar asked Aug 15 '12 13:08

Ree


People also ask

How do I find the root directory path?

In order to get the root directory path, you can use _DIR_ or dirname(). echo dirname(__FILE__); Both the above syntaxes will return the same result.

How do I get to the root directory of my hard drive?

Double-click the hard drive under the right panel's Hard Disk Drives list. For your system drive, double-click the "C" drive. You should now see all the files and folders in the root folder of your hard drive.

How do I get to the root directory of a game?

Right click on the game in the steam library.. then select properties.. local files.. browse local folder. That'll get you there.


2 Answers

The first thing ZF2 does is to change the current dir via chdir(dirname(__DIR__));

This means that every future include is based off of the ROOT PATH of your application and NOT the public folder. Or any other current folder.

Of course this only holds true for PHP-Files.

If you want to define the root path manually, you'd go to /public/index.php and add a line like define('ROOT_PATH', dirname(__DIR__));

As i said before, for INCLUDES this is NOT required though ;) as you're ALWAYS in the root folder when it comes to PHP-Files ;)

like image 166
Sam Avatar answered Oct 14 '22 05:10

Sam


getcwd() works best for me, DIR return the module root. Which isn't much use in this case

like image 35
Smith Avatar answered Oct 14 '22 05:10

Smith