The Blameable
behavior allows you to update one or more authors' fields automatically. This is primarily used to populate data into the created_by
and updated_by
fields. Similar to the Timestamp behavior, you can easily specify some special parameters and essential events for this behavior.
Let us return to the example from the previous section. We also have posts in our blog application. For example, let's assume that our blog model is called BlogPost
. The model has author_id
,
the field which points to who created this post, and updater_id,
the field which points to who updated it. We would like to populate these attributes automatically during the create/update model events. Now you can learn how to do it.
Create a new application using the Composer package manager, as described in the official guide at http://www.yiiframework.com/doc-2.0/guide-start-installation.html.
Set up the database connection and create a table named
blog_post
, as follows...