Defining a Root Path

此生再无相见时 提交于 2019-12-23 20:36:27

问题


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

回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/12754349/defining-a-root-path

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!