PHP搭建自己的MVC框架9 配置加载类
来源:互联网 发布:游族网络 刀剑乱舞 编辑:程序博客网 时间:2024/05/16 11:46
框架中在core 目录下新建config目录 分别是database 和 route 如下图所示:
同时在lib 建conf 类文件
代码如下:
<?phpnamespace core\lib;class conf{ static public $conf = array(); static public function get($name,$file){ /* * 判断配置文件是否存在 * 判断配置是否存在 * 缓存配置 */ if(isset(self::$conf[$file])){ return self::$conf[$file][$name]; }else{ $path= MYMVC .'/core/config/'.$file.'.php'; if(is_file($path)){ $conf = include $path; if(isset($conf[$name])){ self::$conf[$file] = $conf; return $conf[$name]; }else{ throw new \Exception('找不到配置项'.$name); } }else{ throw new \Exception('找不到配置文件'.$file); } } } static public function all($file){ if(isset(self::$conf[$file])){ return self::$conf[$file]; }else{ $path= MYMVC .'/core/config/'.$file.'.php'; if(is_file($path)){ $conf = include $path; self::$conf[$file] = $conf; return $conf; }else{ throw new \Exception('找不到配置文件'.$file); } } }}最后默认的控制器和方法 都是index
数据库的配置也如下 所示:
<?phpreturn array( 'CTRL'=>'index', 'ACTION'=>'index',);
<?phpreturn array( 'DSN'=>'mysql:host=localhost;dbname=test', 'USERNAME'=>'root', 'PASSWD'=>'root',);
0 0
- PHP搭建自己的MVC框架9 配置加载类
- PHP搭建自己的MVC框架4 类自动加载
- 使用PHP搭建自己的MVC框架
- 使用PHP搭建自己的MVC框架
- 使用PHP搭建自己的MVC框架
- 使用PHP搭建自己的MVC框架
- 使用php搭建自己的MVC框架
- 使用PHP搭建自己的MVC框架
- 使用PHP搭建自己的MVC框架
- 使用PHP搭建自己的MVC框架
- PHP搭建自己的MVC框架 1
- PHP搭建自己的MVC框架 2
- PHP搭建自己的MVC框架5 路由类
- php搭建mvc框架二(类的自动加载)
- PHP搭建自己的MVC框架3 入口文件
- PHP搭建自己的MVC框架6 控制器
- PHP搭建自己的MVC框架7 模型层
- PHP搭建自己的MVC框架8 视图层
- js Math.ceil()、Math.floor()和Math.round()
- Android APP崩溃上传日志到服务器并且重启!
- mysql 容灾 灾备 备份
- loadrunner运行脚本提示:You do not have a licence for this Vuser type......
- Java设计模式一
- PHP搭建自己的MVC框架9 配置加载类
- 在Linux终端下进行BT下载
- visual studio 调试时提示 已加载“C:\Windows\SysWOW64\ntdll.dll”。无法查找或打开 PDB 文件。
- Java实现验证码操作小常识
- Node的使用的第一个应用 Node.js的http模块
- OpenGL颜色
- C++模板特化
- Android使用Handler造成内存泄露的分析及解决方法
- [学习笔记]Linux中的定时任务\计划任务-Crontab