Processing model fields with AR event-like methods
Active Record implementation in Yii is very powerful and has many features. One of these features is the event-like methods, which you can use to preprocess model fields before putting them into the database or getting them from a database, as well as to delete data related to the model, and so on.
In this recipe, we will link all URLs in the post text and list all existing Active Record event-like methods.
Getting ready
- 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
post
, as follows:DROP TABLE IF EXISTS 'post'; CREATE TABLE IF NOT EXISTS 'post' ( 'id' INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, 'title' VARCHAR(255) NOT NULL, 'text' TEXT NOT NULL, PRIMARY KEY ('id') );
- Generate the
post
model using...