How to get application's root directory?

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

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 ;)


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


@Sam: I don't really understand your question. Basically the current path equals the ZF2-Apps Root. [...] You can always go up-levels, too via ../

Not exactly. When You create module shared within several applications ex. FileUpload Module in vendor, outside application. You would like to upload file to Application subdirectory not shared module :) In this case __DIR__ equals module path not app path and ../ wouldn,t be good solution ;)

I like ROOT_PATH as You have mentioned:

define('ROOT_PATH', dirname(__DIR__));

or even better:

getcwd()

Need Your Help

Rewrite URL Structure

.htaccess mod-rewrite url-rewriting rewrite

I would like to change the URL structure of my site. My current URL structure is like this:

multiply radio button value and display result

javascript jquery html

I've looked up several examples however to no avail, I need someone to help me format the javascript function for code below. I simply want to select a radio option, and multiply the value by 1.06 ...