首页 > php教程 > PHP源码 > 正文

PHP路由代码

PHP中文网
发布: 2016-05-25 17:13:55
原创
1383人浏览过

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('/index.php/Article','/'.$paths[0].'/');
		}elseif ($this->config['URL_PATHINFO_MODEL']==2){
			define('/index.php/Article','/');
		}
		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路由代码的内容,更多相关内容请关注PHP中文网(www.php.cn)!

js+html5 svg创建点路径生成器工具代码
js+html5 svg创建点路径生成器工具代码

一款js+html5 svg创建点路径生成器工具代码

js+html5 svg创建点路径生成器工具代码 16
查看详情 js+html5 svg创建点路径生成器工具代码

相关标签:
php
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号