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<p> </p><p> 以上就是PHP路由代码的内容,更多相关内容请关注PHP中文网(www.php.cn)!<br></p><div class="aritcle_card flexRow artxards">
<div class="artcardd flexRow">
<a class="aritcle_card_img" rel="nofollow" href="/xiazai/skill13222" title="Build MCP servers and clients for PHP applications with the official PHP SDK"><img
src="https://img.php.cn/upload/skill/001/246/273/6adaf20e352aa140.jpg" alt="Build MCP servers and clients for PHP applications with the official PHP SDK" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a rel="nofollow" href="/xiazai/skill13222" title="Build MCP servers and clients for PHP applications with the official PHP SDK" class="overflowclass">Build MCP servers and clients for PHP applications with the official PHP SDK</a>
<p class="overflowclass">使用官方Model Context Protocol PHP SDK将PHP应用程序功能暴露为MCP工具、资源和提示,用于代理工作流。</p>
</div>
<a rel="nofollow" href="/xiazai/skill13222" title="Build MCP servers and clients for PHP applications with the official PHP SDK" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span>
</a>
</div>
</div><p>
</p>
php免费学习视频:立即使用
踏上前端学习之旅,开启通往精通之路!从前端基础到项目实战,循序渐进,一步一个脚印,迈向巅峰!










