Determining the root path

I am looking for a way to define a config variable as the root path of my website. What's the best way to define it. 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

      

+2


source to share


2 answers


I think,

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

      



will give you what you are looking for no matter what script calls it from where.

On the other hand, I have almost zero experience with codeigniter, which could negatively impact the performance of my proposal.

+1


source


I usually use __DIR__

. For example, if your config file is in the root directory, you can use:

$config['root_path']=__DIR__;

      



Or, if it is located in a subdirectory of the project (for example /anyframework/config/config.php

):

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

      

+4


source







All Articles