API documentation generator for Yii 2

This extension provides an API documentation generator for the Yii framework 2.0.

For license information check the LICENSE-file.

Latest Stable Version Total Downloads

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist yiisoft/yii2-apidoc

or add

"yiisoft/yii2-apidoc": "~2.0.0"

to the require section of your composer.json.

Usage

This extension offers two commands:

  • api to generate class API documentation.
  • guide to render nice HTML pages from markdown files such as the yii guide.

Simple usage for stand alone class documentation:

vendor/bin/apidoc api source/directory ./output

Simple usage for stand alone guide documentation:

vendor/bin/apidoc guide source/docs ./output

You can combine them to generate class API and guide documentation in one place:

# generate API docs
vendor/bin/apidoc api source/directory ./output
# generate the guide (order is important to allow the guide to link to the apidoc)
vendor/bin/apidoc guide source/docs ./output

By default the bootstrap template will be used. You can choose a different template with the --template=name parameter. Currently there is only the bootstrap template available.

You may also add the yii\apidoc\commands\ApiController and GuideController to your console application command map and run them inside of your applications console app.

Advanced usage

The following script can be used to generate API documentation and guide in different directories and also multiple guides in different languages (like it is done on yiiframework.com):

#!/bin/sh

# set these paths to match your environment
YII_PATH=~/dev/yiisoft/yii2
APIDOC_PATH=~/dev/yiisoft/yii2/extensions/apidoc
OUTPUT=yii2docs

cd $APIDOC_PATH
./apidoc api $YII_PATH/framework/,$YII_PATH/extensions $OUTPUT/api --guide=../guide-en --guidePrefix= --interactive=0
./apidoc guide $YII_PATH/docs/guide    $OUTPUT/guide-en --apiDocs=../api --guidePrefix= --interactive=0
./apidoc guide $YII_PATH/docs/guide-ru $OUTPUT/guide-ru --apiDocs=../api --guidePrefix= --interactive=0
# repeat the last line for more languages

Creating a PDF of the guide

You need pdflatex and GNU make for this.

vendor/bin/apidoc guide source/docs ./output --template=pdf
cd ./output
make pdf

If all runs without errors the PDF will be guide.pdf in the output dir.

Special Markdown Syntax

We have a special Syntax for linking to classes in the API documentation. See the code style guide for details.

Creating your own templates

TDB

Using the model layer

TDB

Class Reference

Class Description
yii\apidoc\commands\ApiController Generate class API documentation.
yii\apidoc\commands\GuideController This command can render documentation stored as markdown files such as the yii guide or your own applications documentation setup.
yii\apidoc\components\BaseController Command to render API Documentation files
yii\apidoc\helpers\ApiIndexer ApiIndexer indexes framework API
yii\apidoc\helpers\ApiMarkdown A Markdown helper with support for class reference links.
yii\apidoc\helpers\ApiMarkdownLaTeX A Markdown helper with support for class reference links.
yii\apidoc\helpers\ApiMarkdownTrait Class ApiMarkdownTrait
yii\apidoc\helpers\IndexFileAnalyzer IndexFileAnalyzer analyzes index file with TOC. Typically README.md.
yii\apidoc\helpers\PrettyPrinter Enhances the phpDocumentor PrettyPrinter with short array syntax
yii\apidoc\models\BaseDoc Base class for API documentation information.
yii\apidoc\models\ClassDoc Represents API documentation information for a class.
yii\apidoc\models\ConstDoc Represents API documentation information for a constant.
yii\apidoc\models\Context
yii\apidoc\models\EventDoc Represents API documentation information for an event.
yii\apidoc\models\FunctionDoc Represents API documentation information for a function.
yii\apidoc\models\InterfaceDoc Represents API documentation information for an interface.
yii\apidoc\models\MethodDoc Represents API documentation information for a method.
yii\apidoc\models\ParamDoc Represents API documentation information for a function or method param.
yii\apidoc\models\PropertyDoc Represents API documentation information for a property.
yii\apidoc\models\TraitDoc Represents API documentation information for a trait.
yii\apidoc\models\TypeDoc Base class for API documentation information for classes, interfaces and traits.
yii\apidoc\renderers\ApiRenderer Base class for all API documentation renderers
yii\apidoc\renderers\BaseRenderer Base class for all documentation renderers
yii\apidoc\renderers\GuideRenderer Base class for all Guide documentation renderers
yii\apidoc\templates\bootstrap\ApiRenderer
yii\apidoc\templates\bootstrap\GuideRenderer
yii\apidoc\templates\bootstrap\RendererTrait Common methods for renderers
yii\apidoc\templates\bootstrap\SideNavWidget Nav renders a nav HTML component.
yii\apidoc\templates\bootstrap\assets\AssetBundle The asset bundle for the offline template.
yii\apidoc\templates\bootstrap\assets\JsSearchAsset The asset bundle for the offline template.
yii\apidoc\templates\html\ApiRenderer The base class for HTML API documentation renderers.
yii\apidoc\templates\html\GuideRenderer
yii\apidoc\templates\online\ApiRenderer
yii\apidoc\templates\pdf\GuideRenderer