use CoreConfig;
use CoreRouter;
class Framework {
public static function init() { require_once (__DIR__ . '/functions.php'); // 自動載入設定 spl_autoload_register('self::loadClass'); define("ROOT", getcwd()); define('APP', ROOT . '/' . Config::get('app.app_name')); // 設定時區 ini_set('date.timezone', Config::get('app.timezone')); $router = new Router(); // 載入路由設定 require_once (APP . '/routes.php'); $router->dispatch();}public static function loadClass($className) { // linux上路徑 $className = str_replace("\\", "/", $className); $filename = ROOT . "/" . $className . ".php"; if(is_file($filename)) require_once($filename); else throw new \Exception("$filename Is Not Found");}
}
然後我用str_replace函數替換,總感覺這樣不是最好的方案
回複內容:
use CoreConfig;
use CoreRouter;
class Framework {
public static function init() { require_once (__DIR__ . '/functions.php'); // 自動載入設定 spl_autoload_register('self::loadClass'); define("ROOT", getcwd()); define('APP', ROOT . '/' . Config::get('app.app_name')); // 設定時區 ini_set('date.timezone', Config::get('app.timezone')); $router = new Router(); // 載入路由設定 require_once (APP . '/routes.php'); $router->dispatch();}public static function loadClass($className) { // linux上路徑 $className = str_replace("\\", "/", $className); $filename = ROOT . "/" . $className . ".php"; if(is_file($filename)) require_once($filename); else throw new \Exception("$filename Is Not Found");}
}
然後我用str_replace函數替換,總感覺這樣不是最好的方案
你的方法是對的,不過通常不是替換成/,而是使用常量DIRECTORY_SEPARATOR
使用通用分隔字元,DIRECTORY_SEPARATOR