Using Gii

Before we use Gii, the automatic code generator, we need to install it into our code base.

Installing Gii into the application

Run the following command to fetch the required files to use Gii:

$ php composer.phar require --prefer-dist "yiisoft/yii2-gii:*"

The command-line parameter --prefer-dist is used, so we’ll only get the files needed to use Gii, not develop it.

Now we need to wire Gii into our application:

  1. First, as we’re going to use something installed by Composer in our application, we need the autoloader from Composer. It’s located as a file called autoload.php under the vendor subdirectory. The require call should be placed inside the entry point of our application in the web/index.php file:
    define('YII_DEBUG', true);
    require(__DIR__ ...