user1724167
user1724167

Reputation: 69

Defining a Root Path

I'm looking for a way to define a config variable as being the root path of my website. What's the nicest way to define this. I am using Codeigniter.

$config['root_path'] = ?

This is for my site_config file in my config folder.

/
/dev
/dev/application
/dev/application
/dev/application/config
/dev/application/config/site_config.php
/dev/system/
/dev/assets/
/public_html

Upvotes: 3

Views: 8221

Answers (2)

ultranaut
ultranaut

Reputation: 2140

I think

$config['root_path'] = $_SERVER['DOCUMENT_ROOT'];

will give you what you're looking for, regardless of which script calls it from where.

On the other hand, I have approximately zero experience with codeigniter, which could negatively impact the efficacy of my suggestion.

Upvotes: 1

Wolfgang Stengel
Wolfgang Stengel

Reputation: 2856

I usually use __DIR__. For example, if your configuration file is in the root directory you can use:

$config['root_path']=__DIR__;

Or if it's in a subdirectory of the project (for example /anyframework/config/config.php):

$config['root_path']=dirname(dirname(__DIR__));

Upvotes: 4

Related Questions