PHPackages                             badcat/yii2-api-doc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. badcat/yii2-api-doc

ActiveYii2-extension[API Development](/categories/api)

badcat/yii2-api-doc
===================

api doc for yii2

v1.0.4(4y ago)04MITPHP

Since Mar 23Pushed 4y ago1 watchersCompare

[ Source](https://github.com/lrj525/yii2-api-doc)[ Packagist](https://packagist.org/packages/badcat/yii2-api-doc)[ RSS](/packages/badcat-yii2-api-doc/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (6)Used By (0)

yii2-api-doc
============

[](#yii2-api-doc)

一个针对yii2 restful API的扩展插件 ()

在项目中配置该扩展后，通过读取Controller类中的特定信息，自动生成API说明文档，并可在线进行查看。

Installation
------------

[](#installation)

首选安装方式 [composer](http://getcomposer.org/download/).

执行

```
composer require  badcat/yii2-api-doc

```

或者把

```
"badcat/yii2-api-doc": "^1.0"
```

添加到composer.json中，通过composer install 进行安装

使用方式
====

[](#使用方式)

1. 项目配置
-------

[](#1-项目配置)

在配置文件中加入

```
'bootstrap' => [
        'yii2apidoc'
],
'modules'=>[
    'yii2apidoc'=>[
        'class' => 'badcat\yii2\apidoc\Module', //指定加载模块
        'modules' => ['adminapi','xapi'], //要生成api文档的Module名称
        'docpath' => '/apidoc/' //生成文档的存放目录,相对于web下的目录名，不存在则创建，为空时默认为/apidoc。注意重新生成会清空当前目录下的所有文件
    ]
]

```

2. 生成文档所需特定信息
-------------

[](#2-生成文档所需特定信息)

### Module类配置

[](#module类配置)

在类注释中使用@desc对Module类进行标注，程序会读取@desc的内容，暂只支持读取一行上的内容。

示例

```
/**
 * @desc 后台接口
 */
class Module extends \yii\base\Module
{
    public $controllerNamespace = 'webapp\modules\adminapi\controllers';

    public function init()
    {
        parent::init();
        Yii::configure(Yii::$app, require(__DIR__.'/../../config/adminapi.php'));
    }
}

```

### Controller类配置

[](#controller类配置)

在类注释中使用@desc对Controller类进行标注，程序会读取@desc的内容，暂只支持读取一行上的内容。

示例

```
/**
 * @desc 管理员
 *
 */
class AdminController extends BaseAuthController
{
}

```

### Controller类中的action配置

[](#controller类中的action配置)

在Controller类中的action方法中使用以下方法进行标注。

```
/**
     *
     * @desc 添加管理员
     * @method POST
     * @author lrj
     * @param $user_name | 是 | string | 用户名
     * @param $pwd | 是 | string | 密码
     * @requestEx  {"user_name":"用户名","pwd":"密码"}
     * @returnEx {"user_name":"用户名","pwd":"密码"}
     * @returnParam $user_name | string | 用户名
     * @returnParam $pwd | string | 密码
     **/
    public function actionAdd()
    {
        return $this->result;

    }

```

3. 生成文档
-------

[](#3-生成文档)

把项目使用自己擅长的方式部署后，访问：http://{您的域名}/yii2apidoc/ 打开

4. 查看结果
-------

[](#4-查看结果)

访问：http://{您的域名}/{Module名称}/index.html

5. 最终效果
-------

[](#5-最终效果)

[![图1](https://raw.githubusercontent.com/lrj525/yii2-api-doc/main/yii2apidoc-1.png)](https://raw.githubusercontent.com/lrj525/yii2-api-doc/main/yii2apidoc-1.png)

[![图2](https://raw.githubusercontent.com/lrj525/yii2-api-doc/main/yii2apidoc-2.png)](https://raw.githubusercontent.com/lrj525/yii2-api-doc/main/yii2apidoc-2.png)

[![图3](https://raw.githubusercontent.com/lrj525/yii2-api-doc/main/yii2apidoc-3.png)](https://raw.githubusercontent.com/lrj525/yii2-api-doc/main/yii2apidoc-3.png)

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

5

Last Release

1515d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f18ee72ddd174542f81e7201b12f9c628eedc8e76779f475324d086af7f6c567?d=identicon)[lrj525](/maintainers/lrj525)

---

Top Contributors

[![lirujin](https://avatars.githubusercontent.com/u/111435819?v=4)](https://github.com/lirujin "lirujin (5 commits)")

---

Tags

apidocextensionmoduleyii

### Embed Badge

![Health badge](/badges/badcat-yii2-api-doc/health.svg)

```
[![Health](https://phpackages.com/badges/badcat-yii2-api-doc/health.svg)](https://phpackages.com/packages/badcat-yii2-api-doc)
```

###  Alternatives

[dotzero/yii2-amocrm

Расширение для Yii Framework 2 реализующее клиент для работы с API amoCRM

1639.7k](/packages/dotzero-yii2-amocrm)[skeeks/yii2-google-api

Component for work with google api based on google/apiclient

1243.1k1](/packages/skeeks-yii2-google-api)[mikemadisonweb/yii2-elasticsearch

Yii2 extension for integration with Elasticsearch version 5.0 and above.

153.9k](/packages/mikemadisonweb-yii2-elasticsearch)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
