Code generation

Yii2 provides the powerful module Gii to generate models, controllers, and views, which you can easily modify and customize. It's a really helpful tool for fast and quick development.

In this section we will explore how to use Gii and generate code. For example you have a database with one table named film and you would like to create an application with CRUD operations for this table. It's easy.

Getting ready

  1. Create a new application by using composer as described in the official guide at http://www.yiiframework.com/doc-2.0/guide-start-installation.html.
  2. Download the Sakila database from http://dev.mysql.com/doc/index-other.html.
  3. Execute the downloaded SQLs: first the schema then the data.
  4. Configure the database connection in config/main.php ...

Get Yii2 Application Development Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.