Customizing the ActiveQuery class
By default, all Active Record queries are supported by yii\db\ActiveQuery
. To use a customized query class in an Active Record class, you should override the yii\db\ActiveRecord::find()
method and return an instance of your customized query class.
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, 'lang' VARCHAR(5) NOT NULL DEFAULT 'en', 'title' VARCHAR(255) NOT NULL, 'text' TEXT NOT NULL, PRIMARY KEY ('id') ); INSERT INTO 'post'('id','lang','title','text') VALUES (1,'en_us','Yii news...