php注册自动加载函数

$autoload_func = function($class) {

    $class = str_replace('\\', '/', $class);
    $file_name = dirname(__FILE__).'/../'.$class.'.php';
    include $file_name;

};

spl_autoload_register($autoload_func);

 

在项目入口文件index.php里调用该方法,然后在其他程序页面就可以use了,然后就可以自动加载所需要的类

posted on 2017-02-09 09:23  dongruiha  阅读(1708)  评论(0编辑  收藏  举报

导航