1. TP5框架中使用命令执行指定类中方法
PHP 入口文件 模块/控制器/方法
php /public/index.php index/test
执行结果:成功
2. TP5框架中使用命令执行指定类中方法
php /public/index.php index/test
执行结果:失败(始终不生效、一直跳转至默认首页地址)
3. TP5和TP6框架导致该问题原因
TP5(路径:thinkphp\library\think\Request.php)
TP6(路径:/vendor/topthink/framework/src/think/Request.php)
4. 解决方法
$pathinfo = strpos($this->server('REQUEST_URI'), '?') ? strstr($this->server('REQUEST_URI'), '?', true) : $this->server('REQUEST_URI');
替换为:
$pathinfo = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : '';
再次执行命令,问题解决了!