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 data, assign content from array (form data), and validate data using rules. The Model base class implements the following commonly used features:
- Attribute declaration: By default, every public class member is considered a model attribute; we can access all the members using the
attributes
property of Model. - Attribute labels: Each attribute may be associated with a label for display purposes; we can extend the
attributeLabels()
method to return labels related to public members of Model. - Massive attribute assignment: We can fill the member's content of Model by passing an entire array of values. This is convenient when we need to fill a model with data from the form.
- Scenario-based validation: Model provides...