当前位置:首页 > Web开发 > 正文

$strs ); 5 if ( count ( $d )2)xdie(‘error:param‘ ); 6 $clas

2024-03-31 Web开发

一、找到\vendor\workerman\workerman\WebServer.php 第176行,改为以下内容,增加对html扩展名文件不存在的判断:

if (in_array($workerman_file_extension,[‘php‘,‘html‘]) && !is_file($workerman_file)) { $workerman_file = "{$workerman_root_dir}/index.php"; $workerman_file_extension = ‘php‘; if (!is_file($workerman_file)) { $workerman_file= "{$workerman_root_dir}/index.html"; $workerman_file_extension = ‘html‘; } }

这样以后,只要访谒扩展名为html的文件,,且这个文件不存在,就会自动重定向到index.php,然后再在index.php进行判断就行

二、index.php改革,输出页面前,增加以下判断:

1 //重定向判断 2 $uri=$_SERVER[‘REQUEST_URI‘]; 3 $ext=strtolower(substr($uri,-4,4)); 4 if(is_cli()&&$ext==‘html‘){ 5 $_GET[‘_‘]=substr($uri,1,strlen($uri)-5); 6 }

我访谒的地点是,即访谒index.php?_=Users_login

三、按照$_GET[‘_‘],支解下划线,判断加载哪一个类和类的要领,就行了。好比:

1 $_GET[‘_‘]=isset($_GET[‘_‘])?$_GET[‘_‘]:strcode(‘Index_index‘); 2 $strs=strcode($_GET[‘_‘],‘DECODE‘); 3 if(!$strs)xdie(‘param error.‘); 4 $d=preg_split(‘/[\.\_]/‘,$strs); 5 if(count($d)<2)xdie(‘error:param‘); 6 $class=$d[0].‘Action‘; 7 $action=$d[1];

再加载类并运行就行

php框架workerman伪静态改革详细说明

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/32321.html