框架的搭建之路由类
来源:互联网 发布:素材软件 编辑:程序博客网 时间:2024/04/27 01:47
首先在我们的根目录下创建.htaccess文件:
#开启重写引擎RewriteEngine onRewriteCond %{REQUEST_FILENAME} !-f [NC]RewriteRule ^(.*)$ index.php/$1 [L]
在修改core\imooc.php中的run方法:
<?phpnamespace core;class imooc{public static $classMap = array();public $assign;//基类库static public function run(){$route = new \core\lib\route(); }}
最后完成route.php:
<?phpnamespace core\lib;use core\lib\conf;class route{ public $ctrl; public $action; public function __construct() { /** * 1.隐藏index.php * 2.获取URL参数部分 * 3.返回对用的控制器和方法 */ if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URL'] != '/') { $path = $_SERVER['REQUEST_URI']; $patharr = explode('/',trim($path, '/')); if (isset($patharr[0])) { $this->ctrl = $patharr[0]; } unset($patharr[0]); if (isset($patharr[1])) { $this->action = $patharr[1]; unset($patharr[1]); } else { $this->action = 'index'; } //把url多余的部分转换成 GET $count = count($patharr) + 2; $i = 2; while ($i < $count) { if (isset($patharr[$i + 1])) { $_GET[$patharr[$i] = $patharr[$i + 1]]; } $i = $i +2; } } else { $this->ctrl = 'index'; $this->action = 'index'; } }}
0 0
- 框架的搭建之路由类
- PHP搭建自己的MVC框架5 路由类
- android 路由框架搭建
- android 路由框架搭建
- SnailApp项目---路由框架搭建
- PHP搭建自己的web框架-路由
- vue框架之路由
- 框架的搭建之模型类
- php搭建mvc框架三(路由类)
- 从零开始打造自己的框架 - 路由类
- 我的框架--QiCai(路由类)
- express框架的路由
- web框架之SSH框架的搭建
- web框架之SSH框架的搭建
- beego框架之路由实践
- angularjs 路由---angularjs 搭建前端框架
- 用composer搭建php框架(二)--搭建路由
- UrlRouter路由框架的设计
- C# .net web项目在线升级思路
- ElasticSearch 简单入门
- C语言的集合库C语言STL
- centos 7 tftp配置
- 返回结果集的存储过程 及调用sys_refcursor--结果集
- 框架的搭建之路由类
- GPIO驱动相关笔记
- src 引入中文路径报错404
- python 读取自己的配置
- [C++编程] -- 继承详细解析
- 机器学习--偏差(Bias)、方差(Variance)和误差(error)
- rxjava的map流程
- 联通在信业务SP反向退订
- MVC 数据验证