Yii 2.0如何扩展核心类

Phi*_*ipp 4 yii yii-components yii2

我想扩展类yii\web\Response.所以我在文件夹组件中创建了一个新的类Response ,我尝试覆盖send方法.

namespace app\components;

use Yii;

class Response extends \yii\web\Response{

    public function init(){
        parent::init();
    }

    /**
     * Sends the response to the client.
     */
    public function send()
    { ...
Run Code Online (Sandbox Code Playgroud)

最后,我尝试通过在配置中导入它来导入我的新Response-Class.

$config = [
    'id' => 'basic',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'components' => [
        'import'  => [
            'class' => 'app\components\Response',       
        ], 
Run Code Online (Sandbox Code Playgroud)

为什么它不会像这样工作?

jag*_*ler 5

试试这样:

'components' => [
    'response' => [
        'class' => 'app\components\Response',
    ],
Run Code Online (Sandbox Code Playgroud)