PHP菜鸟博客_共同学习分享PHP技术心得【PHP爱好者】
thinkphp5在cli自带webserver模式下启动传参数的bug修复
2022-8-9 菜鸟站长


Thinkphp5命令行启动的项目(只是在这种模式下启动,为啥要这么启动不用nginx+php-fpm,因为要使用serverless函数计算,nginx下面启动是没有这个问题的。)



#!/usr/bin/env bash



cd /code/tp5/public



php -S 0.0.0.0:9000 router.php



 



在访问的时候不带?id=1这样的参数是没问题的,带上这样的参数就报错提示方法不存在。









 



看意思是把index.html 整体当成的方法名字。



 



 



 



 



解决办法把.html过滤下,入下图替换成空,只要你的方法名字不是.html 就不会有问题的。



D:\phpstudy_pro\WWW\fuliv2\code\tp5\thinkphp\library\think\App.php



 



 



修改的代码如下:



 



//在命令行模式启动下php -S 0.0.0.0:9000 router.php  $actionName,获取到的http://localhost:8000/index/index.shtml?id=3333 获取到的方法名字  是index.shtml ,这里需要过滤下shtml处理wl@20220809,方法名字不要出现.伪静态后缀即可



$action=str_replace(".".config("url_html_suffix"), "", $action);






另外,说明一下只有在上面那样链接的情况下才有问题。以下这么访问没有问题的



http://localhost:8000/index.php/index/index.html?id=111    增加index.php



http://localhost:8000/index/index/index.html?id=111         增加index



http://localhost:8000/index/index?id=111                   去掉html



 

发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容