使用json编码的Codeigniter错误无法修改标头信息 - 已发送的标头

时间:2015-07-06 14:50:27

标签: codeigniter bonfire

我正在使用codeigniter篝火框架来创建网页。在我使用echo json编码的任何地方我都会在错误日志中收到错误,如: -

ERROR - 2015-07-06 17:38:49 --> Severity: Warning  --> Cannot modify header information - headers already sent by (output started at... )

为什么在错误日志文件中生成此错误。它是一个警告生成的示例代码。

public function get_filter()
    {
        if(!empty($_GET))
        {
            $search = $_GET;
            $restaurant = $this->discount_model->get_offer_restaurant_by_discount($_GET);
            echo json_encode($restaurant);
        }
        else{
            $restaurant = $this->discount_model->get_all_discount_restaurants();
            echo json_encode($restaurant);
        }
    }

此处在echo json_encode($ restaurant)行生成错误。如何阻止此错误。

1 个答案:

答案 0 :(得分:1)

Your_Controller.php中的php open标记<?php之前可能有空格

请删除所有文件中<?php标记之前的空格。

相关问题