Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii 2.0 How to extend Core Classes

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?

like image 232
Philipp Avatar asked Apr 28 '15 06:04

Philipp


1 Answers

Try it like this:

'components' => [
    'response' => [
        'class' => 'app\components\Response',
    ],
like image 121
Jap Mul Avatar answered Sep 29 '22 20:09

Jap Mul