Yii 2.0 How to extend core classes

I want to extend the yii \ web \ Response class . So I created a new Response class in the components folder and I am trying to overwrite the submit 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 into config.

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

      

Why won't it work like this?

+3


source to share


1 answer


Try the following:



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

      

+5


source







All Articles