<?php
/**
 * 路由
 * @author 角度 QQ:1286522207
 *
 */
class Dispatcher extends Action {
    private $url;
    private $config;
    function __construct(){
        $this->routerCheck();
    }
    /**
     * 路由检测
     */
    function routerCheck(){
        global $config;
        $this->config=$config;
        $suffix=$this->config['URL_HTML_SUFFIX'];
        //  获取当前路由参数对应的变量
        $paths = (array_filter(explode('/',trim(preg_replace('/\.'.$suffix.'$/','',$_SERVER['PHP_SELF']),'/'))));
        if ($this->config['URL_PATHINFO_MODEL']==1){
            define('__URL__','/'.$paths[0].'/');
        }elseif ($this->config['URL_PATHINFO_MODEL']==2){
            define('__URL__','/');
        }
        if (empty($paths[1])){
            $paths[1]='index';
        }
        if (empty($paths[2])){
            $paths[2]='index';
        }
        if (empty($paths[3])){
            $paths[3]='index';
        }
        $this->Action($paths);
    }
    /**
     * 实例化操作
     */
    function Action($paths){
        if ($paths[1]==$this->config['TMPL_ADMIN_PATH']){
            include APP_PATH.'/'.$this->config['TMPL_ADMIN_PATH'].'/commonAction.php';
            $A=APP_PATH.'/'.$paths[1]."/".$paths[2]."Action.class.php";
            $b=$paths[2];
            @$c=$paths[3];
        }else {
            $A=APP_PATH."/Action/".$paths[1]."Action.class.php";
            $b=$paths[1];
            $c=$paths[2];
        }
        if (is_file($A)){
            include $A;
            $action=$b."Action";
            @$controller = new $action();
            if(method_exists($controller, $c)){
                $controller->$c();
            }else {
                exit('方法不在');
            }
        }else {
            exit('类不在');
        }
 
    }
    /**
     * 解析为$_GET全局变量
     */
    function pathinfo(){
        $pathinfo=(array_filter(explode('/',$this->url)));
        $count=count($pathinfo);
        for($foo=1;$foo<$count;$foo+=2){
            $_GET[$pathinfo[$foo]]=($foo+2)==$count?array_shift(explode('.',$pathinfo[$foo+1])):$pathinfo[$foo+1];
        }
    }
    /**
     * 重排数组
     * @param unknown_type $array
     */
    function Reorder($array){
        $i=0;
        foreach ($array as $row){
            $a[$i++]=$row;
        }
        return $a;
    }
    function __destruct(){
         
    }
}

PHP路由代码的更多相关文章

  1. 数据库分库分表(sharding)系列(五) 一种支持自由规划无须数据迁移和修改路由代码的Sharding扩容方案

    作为一种数据存储层面上的水平伸缩解决方案,数据库Sharding技术由来已久,很多海量数据系统在其发展演进的历程中都曾经历过分库分表的Sharding改造阶段.简单地说,Sharding就是将原来单一 ...

  2. nodejs 用http模块搭建的服务器的路由,以及路由代码的重构过程

    我们打开浏览器浏览网页时,点击上面不同的模块,地址栏中的路由会发生相应的变化,从而,浏览器向服务器发起请求的内容也会发生改变,那么服务端,是如何来做的呢? 服务端也是,通过路由来做出不同的响应的,我们 ...

  3. DB 分库分表(5):一种支持自由规划无须数据迁移和修改路由代码的 Sharding 扩容方案

    作为一种数据存储层面上的水平伸缩解决方案,数据库Sharding技术由来已久,很多海量数据系统在其发展演进的历程中都曾经历过分库分表的Sharding改造阶段.简单地说,Sharding就是将原来单一 ...

  4. node的function函数和路由代码的小例子

    1.node事件循环 事件: const events=require("events"); emt=new events.EventEmitter(); function eve ...

  5. Vue总结第五天:vue-router (使用模块化(创建Vue组件)机制编程)、router-link 标签的属性、路由代码跳转、懒加载、路由嵌套(子路由)、路由传递数据、导航守卫)

    Vue总结第五天:vue-router ✿ 路由(器)目录: □  vue中路由作用 □  vue-router基本使用 □  vue-router嵌套路由 □  vue-router参数传递 □  ...

  6. 利用systemtap学习Linux路由代码

    http://bbs.chinaunix.net/thread-4090162-1-1.html 一.为什么要这样做读kernel route子系统代码,当我弄懂了数据结构之间的关系以及控制流程后,心 ...

  7. 嵌入式 hi3518平台增加路由代码

    <span style="font-family:Courier New;"> /********************************** (C) COPY ...

  8. 《精通MVC5.0》路由笔记

    MVC使用路由系统处理请求的URL.路由系统主要功能 检查请求的URL,并理解该URL对应的控制器和方法 生成URL地址 在MVC程序中有两种方式创建路由:convention-based routi ...

  9. laravel route路由

    基本路由 您的应用程序的绝大多数路由将在 app/routes.php 文件中定义.Laravel 中最简单的路由由一个 URI 和一个闭包调用组成. 基本 GET 路由 代码如下: Route::g ...

随机推荐

  1. jenkins部署springboot多项目

    war包的部署问题不大,这里记录jar包的部署过程: 1:jar包的体积过大问题 pom.xml参考以下配置(依赖包会分离到target/lib/,jar包体积由几十M缩小到几k) <build ...

  2. RT-thread main函数分析

    RT-thread系统的main函数位于startup.c文件中. /** * This function will startup RT-Thread RTOS. */ void rtthread_ ...

  3. 2018 杭电多校3 - M.Walking Plan

    题目链接 Problem Description There are $$$n$$$ intersections in Bytetown, connected with $$$m$$$ one way ...

  4. python将字符串转换成字典的几种方法

    当我们遇到类似于{‘a’:1, 'b':2, 'c':3}这种字符串时,想要把它转换成字典进行处理,可以使用以下几种方法: 1. Python自带的eval函数(不安全) dictstr = '{&q ...

  5. Android 解决setRequestedOrientation之后手机屏幕的旋转不触发onConfigurationChanged方法

    最近在做播放器的时候遇到一个问题,在屏幕方向改变之后需要切换播放器全屏/非全屏的时候,在重写了onConfigurationChanged方法并在manifest.xml配置文件中添加 android ...

  6. POJ3977:Subset——题解(三分+折半搜索)

    http://poj.org/problem?id=3977 题目大意:有一堆数,取出一些数,记他们和的绝对值为w,取的个数为n,求在w最小的情况下,n最小,并输出w,n. ————————————— ...

  7. BZOJ5335:[TJOI2018]智力竞赛——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=5335 小豆报名参加智力竞赛,他带上了n个好朋友作为亲友团一块来参加比赛. 比赛规则如下: 一共有m ...

  8. BZOJ2226 & SPOJ5971:LCMSum——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=2226 题目大意:给定一个n,求lcm(1,n)+lcm(2,n)+……+lcm(n,n). ———— ...

  9. BZOJ2724:[Violet 6]蒲公英——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=2724 输入格式 第一行两个整数n,m,表示有n株蒲公英,m次询问. 接下来一行 n 个空格分隔的整数 ...

  10. linux 文件检索操作

    linux命令太多了,作为一个后端开发人员,常用的也就这几个 uname -a 查看版本 tail tail -f /data/wealth-consignment-service/logs/stat ...