Codeigniter:标头已发送错误

iam*_*esy 4 php codeigniter http-headers

我有一个CI应用程序,具有auth控制器和switchuser功能.基本上它只需要从URI获取ID,从ID获取一些用户数据,分配一些会话数据然后加载视图.

function switch_user(){
    if(!$this->auth_lib->is_admin()){
       $this->session->set_flashdata('status', 'You need to be an administrator to access this page.');
       redirect('auth/login');
    }

    if($id = $this->uri->segment(3)):
            $this->load->model('auth_model', 'auth');
            $username = $this->auth->get_username($id)->account_name;
            $this->session->set_userdata(array('at_id' => $id, 'username' => $username));
            $this->session->set_flashdata('status','User switched.');
    endif;
    $this->load->model('clients_model', 'clients');
    $data['users'] = $this->clients->get_at_clients();
    $this->load->view('auth/switch', $data);
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Message: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\cp\application\controllers\auth.php:130)
Run Code Online (Sandbox Code Playgroud)

第130行是$ username = $ this-> auth-> get_username($ id) - > account_name;

这是模型功能:

function get_username($at_id){
     $portal = $this->load->database('warehouse', TRUE);
     $portal->select('account_name');
     $portal->where('account_id', $at_id);
     $portal->from('wh_account');

     $query = $portal->get()->result();

     return $query[0];
}
Run Code Online (Sandbox Code Playgroud)

我不明白发生了什么.当我在本地运行代码时,我没有收到错误.但是当我远程运行它时,即通过互联网,我得到了标题错误.

任何人都可以帮助确定问题吗?

谢谢,

比利

UPDATE

我实际上在$ username = $ this-> auth-> get_username($ id) - > account_name周围放了一个var_dump; 导致错误的行.我不知道为什么虽然:(

Bry*_*ynJ 8

我会检查你的任何模型,控制器或库中没有关闭PHP标记 - 这通常会导致这种类型的错误.