zoukankan      html  css  js  c++  java
  • PHP路由代码

    <?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(){
             
        }
    }
  • 相关阅读:
    严重: Parse error in application web.xml file at jndi:/localhost/ipws/WEBINF/web.xml java.lang.NoSuchMethodException: org.apache.catalina.deploy.WebXml
    Failed to install .apk on device 'emulator5554': timeout解决方法
    java.lang.NoClassDefFoundError:org.jsoup.Jsoup
    Conversion to Dalvik format failed: Unable to execute dex:解决方法
    apache Digest: generating secret for digest authentication ...
    Description Resource Path Location Type Project has no default.properties file! Edit the project properties to set one.
    android service随机自启动
    MVC3 安装部署
    EF 4.3 CodeBased 数据迁移演练
    SQL Server 2008开启sa账户
  • 原文地址:https://www.cnblogs.com/php-rearch/p/4157443.html
Copyright © 2011-2022 走看看