Codeigniter:标头已发送错误 [英] Codeigniter: headers already sent error

查看:107
本文介绍了Codeigniter:标头已发送错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a CI app that has a auth controller and switchuser function. Basically all it does it take an ID from the URI, get some user data from the ID, assign some session data then load a view.

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);
}

我收到以下错误:

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

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

Line 130 is $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];
}

我不明白发生了什么。当我在本地运行代码,我不会得到的错误。但是当我远程运行,即通过互联网,我得到的标题错误。

I don't understand what's happening. When I run the code locally I don't get the error. But when I run it remotely i.e over the internet I get that headers error.

任何人都可以帮助识别问题?

Can anyone help identify the problem?

感谢,

比利

UPDATE

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

I had actually put a var_dump around the $username = $this->auth->get_username($id)->account_name; line which was causing the error. I don't know know why though :(

推荐答案

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

I would check that you have no closing PHP tag in any of your models, controllers or libraries - this will often cause this type of error.

这篇关于Codeigniter:标头已发送错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆