小编Phi*_*ipp的帖子

Yii 2.0如何扩展核心类

我想扩展类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)

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

yii yii-components yii2

4
推荐指数
1
解决办法
2041
查看次数

标签 统计

yii ×1

yii-components ×1

yii2 ×1