Yii2 扩展或替换核心类 [英] Yii2 extend or replace core class

查看:30
本文介绍了Yii2 扩展或替换核心类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用我自己的类扩展或替换 yii\db\ActiveQuery 并让整个应用程序使用它.

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

这是为了在这个 GitHub 问题.

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?

推荐答案

使用 依赖注入容器为此.

写下您的应用程序引导代码:

Write down in your application bootstrap code:

Yii::$container->set('yii\db\ActiveQuery', 'app\components\ActiveQuery');

这篇关于Yii2 扩展或替换核心类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆