検索

PHP路由代码

May 25, 2016 pm 05:13 PM

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[&#39;URL_HTML_SUFFIX&#39;];
		//  获取当前路由参数对应的变量
		$paths = (array_filter(explode(&#39;/&#39;,trim(preg_replace(&#39;/\.&#39;.$suffix.&#39;$/&#39;,&#39;&#39;,
		$_SERVER[&#39;PHP_SELF&#39;]),&#39;/&#39;))));
		if ($this->config[&#39;URL_PATHINFO_MODEL&#39;]==1){
			define(&#39;/index.php/Article&#39;,&#39;/&#39;.$paths[0].&#39;/&#39;);
		}elseif ($this->config[&#39;URL_PATHINFO_MODEL&#39;]==2){
			define(&#39;/index.php/Article&#39;,&#39;/&#39;);
		}
		if (empty($paths[1])){
			$paths[1]=&#39;index&#39;;
		}
		if (empty($paths[2])){
			$paths[2]=&#39;index&#39;;
		}
		if (empty($paths[3])){
			$paths[3]=&#39;index&#39;;
		}
		$this->Action($paths);
	}
	/**
	 * 实例化操作
	 */
	function Action($paths){
		if ($paths[1]==$this->config[&#39;TMPL_ADMIN_PATH&#39;]){
			include APP_PATH.&#39;/&#39;.$this->config[&#39;TMPL_ADMIN_PATH&#39;].&#39;/commonAction.php&#39;;
			$A=APP_PATH.&#39;/&#39;.$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(&#39;方法不在&#39;);
			}
		}else {
			exit(&#39;类不在&#39;);
		}

	}
	/**
	 * 解析为$_GET全局变量
	 */
	function pathinfo(){
		$pathinfo=(array_filter(explode(&#39;/&#39;,$this->url)));
		$count=count($pathinfo);
		for($foo=1;$foo<$count;$foo+=2){
$_GET[$pathinfo[$foo]]=($foo+2)==$count?array_shift(explode(&#39;.&#39;,$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路由代码的内容,更多相关内容请关注PHP中文网(www.php.cn)!

声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

EditPlus 中国語クラック版

EditPlus 中国語クラック版

サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません

Dreamweaver Mac版

Dreamweaver Mac版

ビジュアル Web 開発ツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

MantisBT

MantisBT

Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール