php auto_load mvc 接口框架(原创)
2024-10-01 08:09:50
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);
最新文章
- springMVC接收参数的几种方式
- jquery 巧用json传参
- java 中如何声明线程安全的集合 set, map 和list
- linker command failed with exit code 1 (use -v to see invocation)解决办法
- LoadRunner11录制APP脚本(2)
- Zabbix自带模板监控MySQL
- laravel框架总结(五) -- 服务提供者(提及契约Contracts)
- SIP中OPTIONS方法的用法及示例
- ibatis.net demo
- [Linux/Ubuntu] vi/vim 使用方法讲解(转载)
- 用Eclipse和GDB构建ARM交叉编译和在线调试环境
- JS(移动端)自己封装移动端一些常用方法
- 【JAVASCRIPT】event对象
- 用Python做大批量请求发送
- python __call__或者说func()()的理解
- 月赛 &;&; SX_ACM 惨痛教训
- centos7.2 源码编译安装php7.2.4 apache2.4.37 https证书安装
- jQuery 插件使用记录
- Bash:常用命令工具-tr命令
- linux/unix 段错误捕获_转