我写接口写到一半,发觉整个apidoc方便一些,然后就安装了扩展hg/apidoc ,但是我的tp是开了强制路由的。apidoc跑不起来,有哪位大虾,能解决一下我的问题嘛?
在ThinkPHP 6.0中,使用thinkapidoc生成API文档,并开启强制路由时,需要进行如下配置:
config/app.php
文件中开启强制路由,将url_route_must
配置项改为true
:'url_route_must' => true,
composer.json
文件中加入下面的代码,然后执行composer update
命令安装依赖库:"require-dev": {
"tiderjian/think-apidoc": "^1.0"
}
config/app.php
文件中添加自定义配置项,如下所示:return [
// other configs
'think\apidoc\ServiceProvider',
// 自定义配置项
'apidoc' => [
'title' => '接口文档', // 文档标题
'version' => 'v1.0', // 文档版本
'controller_dir' => 'app\api\controller', // 控制器目录
'exclude_dir' => ['base', 'extra'], // 排除的目录
'output_dir' => 'public/apidoc', // 生成文档的输出目录
'theme' => 'default', // 文档主题
'suffix' => '.html', // 文档后缀
'debug' => true, // 调试模式
],
];
其中,controller_dir
是API控制器文件目录,exclude_dir
是需要排除的目录,output_dir
是文档输出目录,theme
是文档主题,suffix
是文档后缀,debug
是调试模式控制开关。
php think apidoc
命令,生成API文档。在生成API文档前,需要先运行一次php think route:list
命令,生成runtime/route.php
文件。否则,将无法正确生成API文档。以上就是在开启强制路由时,使用thinkapidoc生成API文档的配置方法。