autoload.php
<?php function framework_autoload($className){ $className=str_replace('\','/',$className); include_once($className.'.class'.'.php'); } spl_autoload_register('framework_autoload');
init.php
<?php require_once($_SERVER['DOCUMENT_ROOT'] . "/comm.php"); // 开启调试模式 建议开发阶段开启 部署阶段注释或者设为false define('APP_DEBUG',true); APP_DEBUG?error_reporting(E_ALL):error_reporting(0); // 定义应用目录 define('APP_PATH',$_SERVER['DOCUMENT_ROOT'] . "/new_framework/"); //定义按照类名自动加载的include起始路径 $autoLoadIncludePath=array(APP_PATH); set_include_path(get_include_path() . PATH_SEPARATOR .implode(PATH_SEPARATOR,$autoLoadIncludePath)); //php自动加载 require_once(APP_PATH."BLL/autoload.php"); //mvc 处理 $c=$_REQUEST['c']; $controller='Controller\'.$c.'Controller'; $action=$_REQUEST['a']; if(!class_exists($controller)){ $res['code']=1000; $res['msg']=$c.'控制器不存在!'; }else if(!method_exists($controller,$action)){ $res['code']=1001; $res['msg']=$action.'方法不存在!'; }else{ $controllerObj=new $controller(); $res=$controllerObj->$action(); } echo json_encode($res);