gengshaojing 2018-02-25 17:40:46 6547次浏览 3条回复 0 0 0

代码


<?php

namespace frontend\controllers;

class PostController extends BaseController
{

    public function actionIndex()
    {
        echo 123;
    }
}

输出

123

An Error occurred while handling another error:
yii\web\HeadersAlreadySentException: Headers already sent in /Users/gengshaojing/www/basic/frontend/controllers/PostController.php on line 10. in /Users/gengshaojing/www/basic/vendor/yiisoft/yii2/web/Response.php:366
Stack trace:
#0 /Users/gengshaojing/www/basic/vendor/yiisoft/yii2/web/Response.php(339): yii\web\Response->sendHeaders()
#1 /Users/gengshaojing/www/basic/vendor/yiisoft/yii2/web/ErrorHandler.php(135): yii\web\Response->send()
#2 /Users/gengshaojing/www/basic/vendor/yiisoft/yii2/base/ErrorHandler.php(111): yii\web\ErrorHandler->renderException(Object(yii\web\HeadersAlreadySentException))
#3 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\web\HeadersAlreadySentException))
#4 {main}
Previous exception:
yii\web\HeadersAlreadySentException: Headers already sent in /Users/gengshaojing/www/basic/frontend/controllers/PostController.php on line 10. in /Users/gengshaojing/www/basic/vendor/yiisoft/yii2/web/Response.php:366
Stack trace:
#0 /Users/gengshaojing/www/basic/vendor/yiisoft/yii2/web/Response.php(339): yii\web\Response->sendHeaders()
#1 /Users/gengshaojing/www/basic/vendor/yiisoft/yii2/base/Application.php(392): yii\web\Response->send()
#2 /Users/gengshaojing/www/basic/frontend/web/index.php(17): yii\base\Application->run()
#3 {main}
  • 回复于 2018-02-25 22:45 举报

    错误提示已经很清楚了,提示响应的头信息发送时已经有头部发送过了,你检查一下是不是引用的其他文件里有输出,特别是空白字符,很难发现。或者php文件编码是不是采用了utf8 with BOM

  • 回复于 2018-03-10 12:20 举报

    技术QQ交流群:294088839。

  • 回复于 2019-02-27 14:24 举报

    echo 123;
    exit;

您需要登录后才可以回复。登录 | 立即注册