
Yii2 Application Development Cookbook
By :

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.
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 Gii.
Add the following method to models/Post...
Change the font size
Change margin width
Change background colour