php7开启路由模式,关于结合 TP5 使用时路由开启强制模式后无法正常启动的问题...

编程知识 更新时间:2023-05-02 23:24:50

环境:

ThinkPHP 5.0.15;

PHP 5.5.8

系统为 Windows 7 (64 bit)

其中,当配置如下时:

// config.php:

'url_route_on' => true,

'route_complete_match' => true,

'url_route_must' => true,

// route.php:

'__miss__' => 'index/Index/r404',

开启服务出现如下报错:

[think\exception\HttpException]

module not exists:index

当未定义 MISS 路由时出现如下报错:

[think\exception\RouteNotFoundException]

Route Not Found

修改配置,关闭路由的强制模式和去除MISS路由后恢复正常运行,

初步分析,该异常是由 tp5/thinkphp/library/think/App.php 第 535 或 637 行抛出异常。

最后跟踪框架代码发现 tp5/thinkphp/library/think/Request.php 的 pathinfo() 方法中有一层判断,如果为 php_cli 模式下,则使用 php 命令后的第二个参数作为 pathinfo 。

代码摘自 TP5 框架:

} elseif (IS_CLI) {

// CLI模式下 index.php module/controller/action/params/...

$_SERVER['PATH_INFO'] = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : '';

}

所以, you_app_path/worker/start-for-win.bat 中的:

php ./starter/start_register.php ./starter/start_gateway.php ./starter/start_business.php

pause

php 命令后的 ./starter/start_gateway.php 将被当作 pathinfo 处理。

目前,我的解决方案是:

配置文件中,根据 you_app_path/worker/starter/start_business.php (从 evan-li/think-gateway-for-win 中复制):

// you_app_path/worker/starter/start_business.php:

define('BIND_MODULE','worker/Starter');

define('START_BUSINESS', true);

// 根据上面定义的常量动态改变配置。

// config.php:

'url_route_must' => defined('BIND_MODULE') && defined('START_BUSINESS') ? false : true,

// route.php

defined('START_BUSINESS') or \think\Route::miss('index/Index/r404');

通过这种方式暂时解决了问题,不知道作者是否也有遇到这样的问题,以及是否有更加优雅的解决方法。

更多推荐

php7开启路由模式,关于结合 TP5 使用时路由开启强制模式后无法正常启动的问题...

本文发布于:2023-04-29 08:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/1e09622a36efce32a0009198fb59a5da.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   模式   无法正常

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 110541文章数
  • 28156阅读数
  • 0评论数