O'Reilly logo

Yii2 By Example by Fabrizio Caldarelli

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

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 ...

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