admin 管理员组文章数量: 1184232
环境:
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 使用时路由开启强制模式后无法正常启动的问题... 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1754635388a3023851.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论