By now, you should be familiar with using the Gii tool to create models for our newly created tables. Go ahead and create the models for Users
, Reminders
, and Events
. After creating each model, there are several changes we need to make to each of them.
The first change that will need to be made to our newly created models is the automatic setting of the created and updated timestamp. In previous chapters, we modified the beforeSave()
method to do this; however, Yii provides an easier way to implement this feature that is database-agnostic and reduces the amount of code we have to add to our models. To do this, we are going to attach a behavior to each of our models.
Behaviors in Yii are objects that have methods that can be attached to a component (in our case, a model). These behaviors then listen for certain events on the attached component (such as the beforeSave()
method) and execute when that event is triggered.