PHP路由代碼

來源:互聯網
上載者:User

標籤:des   io   ar   sp   for   on   div   bs   cti   

<?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路由代碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.