O'Reilly logo

Web Application Development with Yii 2 and PHP by Jeffrey Winesett, Mark Safronov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:
    <?php
    define('YII_DEBUG', true);
    
    require(__DIR__ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required