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

环境:

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');

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值