Making php includes work in a sub-directory

后端 未结 4 1554
北海茫月
北海茫月 2020-12-29 12:57

Ok, I am creating an admin interface for my custom blog at the url /admin.

Is it possible for me to be able to use the same includes (including autoload), as the roo

4条回答
  •  北海茫月
    2020-12-29 13:22

    Another option that I've used for functions.php in the past is a class autoloader.

    //Class Autoloader
    spl_autoload_register(function ($className) {
    
        $className = strtolower($className);
        $path = "includes/{$className}.php";
    
        if (file_exists($path)) {
    
            require_once($path);
    
        } else {
    
            die("The file {$className}.php could not be found.");
    
        }
    });
    

    This works under certain circumstances and has been helpful to me in the past when I don't want to define an absolute $root url.

提交回复
热议问题