您可以做的是在您的 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';
您应该bootstrap.php
做的是在您的文件夹中放置一个名为的Modules
文件。
将以下代码添加到您的索引文件中,而不是上面的代码。
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 变体都有一个常量。
有关这种引导技术的演示,请参阅PHP PowerTools 样板。