ThinkPHP5/6 自动API文档,tp5安装自动文档需注意版本号

- 6.0执行 1.7开始只支持tp6
composer require weiwei/api-doc
- 5.0或者5.1
composer require weiwei/api-doc 1.6.2

1.非根目录安装需修改2处:

        a.

        b.

2.根目录安装####2、配置参数

  • 5.0安装好扩展后在 application\extra\ 文件夹下会生成 doc.php 配置文件(
  •         很多朋友是改了默认的“application”的,所以是没法自动生成的,那就要手动从vendor/weiwei/api-doc/src/doc.php拿出来,放到extra文件夹下,这样才会生效
  • 5.1安装好扩展后在 application\config\ 文件夹下会生成 doc.php 配置文件
  • 6.0安装好扩展后在 config\ 文件夹下会生成 doc.php 配置文件
  • 在controller参数中添加对应的类
    'controller' => [
        'app\\api\\controller\\Demo' //这个是控制器的命名空间+控制器名称
    ]

####3、在相关接口类中增加注释参数( group 参数将接口分组,可选)

  • 方法如下:返回参数支持数组及多维数组
<?php
namespace app\index\controller;
use think\Controller;

/**
 * @title 测试demo
 * @description 接口说明
 * @group 接口分组
 * @header name:key require:1 default: desc:秘钥(区别设置)
 * @param name:public type:int require:1 default:1 other: desc:公共参数(区别设置)
 */
class Demo extends Controller
{
    /**
     * @title 测试demo接口
     * @description 接口说明
     * @author 开发者
     * @url /index/demo
     * @method GET
     *
     * @header name:device require:1 default: desc:设备号
     *
     * @param name:id type:int require:1 default:1 other: desc:唯一ID
     *
     * @return name:名称
     * @return mobile:手机号
     * @return list_messages:消息列表@
     * @list_messages message_id:消息ID content:消息内容
     * @return object:对象信息@!
     * @object attribute1:对象属性1 attribute2:对象属性2
     * @return array:数组值#
     * @return list_user:用户列表@
     * @list_user name:名称 mobile:手机号 list_follow:关注列表@
     * @list_follow user_id:用户id name:名称
     */
    public function index()
    {
        //接口代码
        $device = $this->request->header('device');
        echo json_encode(["code"=>200, "message"=>"success", "data"=>['device'=>$device]]);
    }

    /**
     * @title 登录接口
     * @description 接口说明
     * @author 开发者
     * @url /api/demo
     * @method GET
     * @module 用户模块

     * @param name:name type:int require:1 default:1 other: desc:用户名
     * @param name:pass type:int require:1 default:1 other: desc:密码
     *
     * @return name:名称
     * @return mobile:手机号
     *
     */
    public function login(Request $request)
    {
        //接口代码
        $device = $request->header('device');
        echo json_encode(["code"=>200, "message"=>"success", "data"=>['device'=>$device]]);
    }
}

####4、在浏览器访问http://你的域名/doc 或者 http://你的域名/index.php/doc 查看接口文档

 TP6在浏览器访问http://你的域名/doc/index    一定要加/index

TP6 css js 记载不到,修改路径

####5、预览

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

暴雨课堂

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值