Yii 2.0 How to extend Core Classes

流过昼夜 提交于 2019-12-07 09:00:49

问题


I want to extend the class yii\web\Response. So I created a new class Response in the folder components and I try to overwrite the send method.

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()
    { ...

Finally I tried to import my new Response-Class by importing it in the config.

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

Why is it not going to work like this?


回答1:


Try it like this:

'components' => [
    'response' => [
        'class' => 'app\components\Response',
    ],


来源:https://stackoverflow.com/questions/29912272/yii-2-0-how-to-extend-core-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!