Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 extend or replace core class

Tags:

yii2

I'd like to either extend or replace yii\db\ActiveQuery with my own class and have the entire application use it.

This is to bring in the @alias functionality referenced by CedricYii at the bottom of this GitHub issue.

Due to the private nature of some of the changed functions, I'll probably have to replace it.

Is this possible? Or will I have to fork the repository?

like image 618
Arth Avatar asked Jul 12 '26 15:07

Arth


1 Answers

Use Dependency Injection Container for this.

Write down in your application bootstrap code:

Yii::$container->set('yii\db\ActiveQuery', 'app\components\ActiveQuery');
like image 133
SilverFire Avatar answered Jul 15 '26 02:07

SilverFire