# real-apidoc **Repository Path**: jinan-jimeng-network_0/real-apidoc ## Basic Information - **Project Name**: real-apidoc - **Description**: real-apidoc - **Primary Language**: PHP - **License**: BSD-3-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2021-10-21 - **Last Updated**: 2023-05-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 基础介绍 基于tp6的api生成模块,参考fastadmin的api模块 # 引用 下载到tp6的extend\jmwl下 ```php use jmwl\realapidoc\Builder; use think\facade\View; ``` # 使用 这里是所有的需要生成api的控制器路径啦、所以,你可以先获取到模块下的所有控制器 Builder(["\\app\\admin\\controller\\Demo","\\app\\admin\\controller\\Index"]) ```php $title="类名"; $url="http://real-think.jmwl51.com"; //这里是所有的需要生成api的控制器路径啦 $builder = new Builder(["\\app\\admin\\controller\\command"]); $content = $builder->render(root_path()."/extend/jmwl/realapidoc/template/index.html",$title,$url); // dump($content); die; View::assign('config',$content["config"]); View::assign('docslist',$content["docsList"]); View::assign('lang',$content["lang"]); return View(); ``` # 视图 文件中的index.html就是视图啦,放到正确的位置 我放在了 app\admin\view\api\index.html 对应的控制器自然是 admin下的api控制器啦 # 控制器注释 |名称| 描述| 示例| |-|-|-| |@ApiSector |API分组名称| (测试分组)| |@ApiRoute| API接口URL,此@ApiRoute只是基础URL| (/api/test)| |@ApiInternal| 忽略的控制器,表示此控制将不加入API文档| 无| |@ApiWeigh| API方法的排序,值越大越靠前| (99)| # 控制器方法注释 |名称 |描述 |示例| |-|-|-| |@ApiTitle| API接口的标题,为空时将自动匹配注释的文本信息 |(测试标题)| |@ApiSummary| API接口描述| (测试描述)| |@ApiRoute| API接口地址,为空时将自动计算请求地址| (/api/test/index)| |@ApiMethod| API接口请求方法,默认为GET| (POST)| |@ApiSector| API分组,默认按钮控制器或控制器的@ApiSector进行分组| (测试分组)| |@ApiParams| API请求参数,如果在@ApiRoute中有对应的{@参数名},将进行替换| (name="id", type="integer", required=true, description="会员ID")| |@ApiHeaders| API请求传递的Headers信息| (name=token, type=string, required=true, description="请求的Token")| |@ApiReturn |API返回的结果示例 |({"code":1,"msg":"返回成功"})| |@ApiReturnParams| API返回的结果参数介绍| (name="code", type="integer", required=true, sample="0")| |@ApiReturnHeaders| API返回的Headers信息| (name="token", type="integer", required=true, sample="123456")| |@ApiInternal |忽略的方法,表示此方法将不加入文档| 无| |@ApiWeigh| API方法的排序,值越大越靠前| (99)| # 示范 ```php success("返回成功", $this->request->request()); } } ```