如何存储我的“子站点"的根目录 [英] How to store the root of my "subsite"
问题描述
我需要将我的网络应用"添加到现有网站.它将被放置在一个单独的文件夹中.
I need to add my "web app" to an existing site. It will be placed in a separate folder.
为我的应用定义根目录的最佳方式是什么?它不会与网站的其余部分进行交互.
What is the best way to define the root for my app? It will have no interaction with the rest of the site.
我想在我的根目录中创建一个 .php
脚本并执行如下操作:
I thought of just creating a .php
script in my root and do something like:
define('ROOT_DIR', dirname(__FILE__));
然后将该文件包含在所有其他脚本中.
And then include this file in all other scripts.
这是正确的做法吗?
推荐答案
FROM PHP DOC 在 dirname(__FILE__)
或 __DIR__
给定一个包含文件或目录路径的字符串,此函数将返回父目录的路径.
Given a string containing the path of a file or directory, this function will return the parent directory's path.
这可以根据我们的结构和单个配置文件轻松更改
This can easily change depending on our be structure and one single config file
例如
http://example.com = /public_html
http://example.com/mobile = /public_html/mobile
我的建议..硬编码,因为它总是固定的
My Advice .. HARD CODE it since it is always fixed
define('ROOT_DIR','/public_html');
如果您在 /public_html/class/HelloWord.class.php
无论您当前的目录如何,您都可以轻松访问它
You can easy access it has the following no matter your current directory
ROOT_DIR . '/class/HelloWord.class.php' ;
这篇关于如何存储我的“子站点"的根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!