什麼你可以做的,就是包括以下行到你的index.php文件路徑:
define("LOCAL_PATH_MODULES", dirname(__DIR__));
define("LOCAL_PATH_APP", dirname(LOCAL_PATH_MODULES));
define("LOCAL_PATH_CONFIG", MODULES_PATH . DIRECTORY_SEPARATOR . 'config');
require LOCAL_PATH_CONFIG . DIRECTORY_SEPARATOR . 'config.php';
什麼你應該這樣做,是在您的Modules
文件夾中放入一個名爲bootstrap.php
的文件。
代替上面的代碼,將以下代碼添加到您的索引文件中。
define("LOCAL_PATH_BOOTSTRAP", dirname(__DIR__));
require dirname(__DIR__) . 'bootstrap.php';
現在,這種添加到您的引導文件:
// -----------------------------------------------------------------------
// DEFINE SEPERATOR ALIASES
// -----------------------------------------------------------------------
define("URL_SEPARATOR", '/');
define("DS", DIRECTORY_SEPARATOR);
define("PS", PATH_SEPARATOR);
define("US", URL_SEPARATOR);
// -----------------------------------------------------------------------
// DEFINE ROOT PATHS
// -----------------------------------------------------------------------
define("RELATIVE_PATH_ROOT", '');
define("LOCAL_PATH_ROOT", $_SERVER["DOCUMENT_ROOT"]);
define("HTTP_PATH_ROOT",
isset($_SERVER["HTTP_HOST"]) ?
$_SERVER["HTTP_HOST"] : (
isset($_SERVER["SERVER_NAME"]) ?
$_SERVER["SERVER_NAME"] : '_UNKNOWN_'));
// -----------------------------------------------------------------------
// DEFINE RELATIVE PATHS
// -----------------------------------------------------------------------
define("RELATIVE_PATH_APP", dirname(LOCAL_PATH_BOOTSTRAP));
define("RELATIVE_PATH_LIBRARY", RELATIVE_PATH_APP . DS . 'Lib');
define("RELATIVE_PATH_ADMIN", RELATIVE_PATH_APP . DS . 'Admin');
define("RELATIVE_PATH_CONFIG", RELATIVE_PATH_APP . DS . 'Config');
define("RELATIVE_PATH_MODULES", RELATIVE_PATH_APP . DS . 'Modules');
define("RELATIVE_PATH_ASSET", RELATIVE_PATH_APP . DS . 'Includes');
define("RELATIVE_PATH_ASSET_IMG", RELATIVE_PATH_ASSET . DS . 'Images');
define("RELATIVE_PATH_ASSET_CSS", RELATIVE_PATH_ASSET . DS . 'CSS');
define("RELATIVE_PATH_ASSET_JS", RELATIVE_PATH_ASSET . DS . 'JS');
// -----------------------------------------------------------------------
// DEFINE LOCAL PATHS
// -----------------------------------------------------------------------
define("LOCAL_PATH_APP", LOCAL_PATH_ROOT . RELATIVE_PATH_APP);
define("LOCAL_PATH_LIBRARY", LOCAL_PATH_ROOT . RELATIVE_PATH_LIBRARY);
define("LOCAL_PATH_ADMIN", LOCAL_PATH_ROOT . RELATIVE_PATH_ADMIN);
define("LOCAL_PATH_CONFIG", LOCAL_PATH_ROOT . RELATIVE_PATH_CONFIG);
define("LOCAL_PATH_MODULES", LOCAL_PATH_ROOT . RELATIVE_PATH_MODULES);
define("LOCAL_PATH_ASSET", LOCAL_PATH_ROOT . RELATIVE_PATH_ASSET);
define("LOCAL_PATH_ASSET_IMG", LOCAL_PATH_ROOT . RELATIVE_PATH_ASSET_IMG);
define("LOCAL_PATH_ASSET_CSS", LOCAL_PATH_ROOT . RELATIVE_PATH_ASSET_CSS);
define("LOCAL_PATH_ASSET_JS", LOCAL_PATH_ROOT . RELATIVE_PATH_ASSET_JS);
// -----------------------------------------------------------------------
// DEFINE URL PATHS
// -----------------------------------------------------------------------
define("HTTP_PATH_APP", HTTP_PATH_ROOT . RELATIVE_PATH_APP);
define("HTTP_PATH_LIBRARY", false);
define("HTTP_PATH_ADMIN", false);
define("HTTP_PATH_CONFIG", false);
define("HTTP_PATH_MODULES", false);
define("HTTP_PATH_ASSET", HTTP_PATH_ROOT . RELATIVE_PATH_ASSET);
define("HTTP_PATH_ASSET_IMG", HTTP_PATH_ROOT . RELATIVE_PATH_ASSET_IMG);
define("HTTP_PATH_ASSET_CSS", HTTP_PATH_ROOT . RELATIVE_PATH_ASSET_CSS);
define("HTTP_PATH_ASSET_JS", HTTP_PATH_ROOT . RELATIVE_PATH_ASSET_JS);
現在,你有兩個在應用程序中最重要的路徑本地和HTTP的變體恆定。
請參閱the PHP PowerTools Boilerplate瞭解該引導技術的演示。
創建文件路徑字符串時,應始終使用PHP內置常量DIRECTORY_SEPARATOR。 –
一旦文件被鏈接,我將使用各種內置函數。 – TomPHP