Tabular input

In this section, we will show you how to use a model to save and validate related models. Sometimes you will need to handle multiple models of the same kind in a single form.

For instance, we have contests and prizes for contests. Any contest might contain an unlimited number of prizes. So, we need the ability to create a contest with prizes, validate them, display all errors, and save the primary model (contest model) and all related models (prize models) to the database.

Getting ready

  1. Create a new application by using the Composer package manager, as described in the official guide at http://www.yiiframework.com/doc-2.0/guide-start-installation.html.
  2. Create migrations for contest and prize tables with the following commands:
    ./yii migrate/create ...

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.