我想扩展课程 yii \ web \ Response 。所以我在文件夹 components 中创建了一个新类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()
{ ...
最后,我尝试通过在配置中导入新的Response-Class来导入它。
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'components' => [
'import' => [
'class' => 'app\components\Response',
],
为什么它不能像这样工作?
答案 0 :(得分:5)
试试这样:
'components' => [
'response' => [
'class' => 'app\components\Response',
],