Creating a model
Our model will have the following methods:
Here, we’re going to use MySQL and Squel.
First, let’s define
read method returns an object with two properties:
count(the number of returned records).
Pay attention to this part:
The value of
records is an array consisting of arrays that store a record id as their first element and
a record as the second one.
Let’s define methods for validation:
Next, we’ll define
getRecord method returns a single record.
Here’s the code for
If data is valid,
create returns the id of the inserted record. Otherwise, it returns validation errors.
Let’s define the
This method returns validation errors and updated records. The return value format is the same as for the
Validation is used to highlight the form fields which were filled wrongly.
Updated records are used for updating of the grid.
Finally, let’s define
The return value of
delete can be different. It depends on the definition of this method in the client model.