Chapter 4. Creating a Room through Forms

This chapter explains how to write a model class to store data that will be sent from View to Controller using a form, with validating input, formatting data, and uploading files. In this chapter, we will cover the following topics:

  • Creating a Model
    • Example – a model to store room data
  • Using ActiveForm
    • Example – creating a new room from the HTML form
  • Formatting date, time, and numbers
  • Uploading files
    • Example – uploading an image of the room

Creating a Model

The first step to manipulate data between View and Controller is to create a Model. A Model is a class that extends the Model class located under yii\base\, the base used for data models.

This is a suitable class for providing simple solutions in order to encapsulate ...

Get Yii2 By Example 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.