PHP 自动载入,实例化对象时自动include类文件(spl_autoload_register)

来源:互联网 发布:mac文档怎么转换格式 编辑:程序博客网 时间:2024/06/14 14:13

echo getcwd();  //获取当前工作目录路径。  "D:/WWW/web1"

<?php//核心启动类class Framework{//run方法public static function run(){self::init();self::autoload();self::dispatch();}//初始化方法private static function init(){//。。。。。。}//路由分发private static function dispatch(){$controller_name = "IndexController";$action_name = "indexAction";$controller = new $controller_name();  //只有new时,才会自动调用load函数。$controller->$action_name();}//自动载入,不实例化对象不会load。实例化对象,找不到类名时,才会load。private static function autoload(){//spl_autoload_register(array(__CLASS__,"load"));spl_autoload_register('self::load');}//载入函数(include)public static function load($classname){include CUR_CONTROLLER_PATH."{$classname}.class.php";}}?>






原创粉丝点击