Codeigniter错误消息无法修改标头信息 [英] Codeigniter error message Cannot modify header information
问题描述
运行我的php CodeIgniter项目时收到以下错误消息:
I got this error message when i run my php CodeIgniter project:
遇到PHP错误
A PHP Error was encountered
严重性:警告
消息:无法修改标题信息-
已发送的标题(输出从
C开始:\AppServ\www\tree\application\models\mtree.php:17)
Message: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\tree\application\models\mtree.php:17)
文件名:core / Common.php
Filename: core/Common.php
行号:442
第17行:
echo $row->members_id . "</br>";
这是我的模型函数:
function convert_all() {
$this->db->empty_table('table1');
$this->db->empty_table('table2');
$this->db->query("INSERT INTO `table1` (`members_id`, `members_username`);
$query = $this->db->get('table2');
foreach ($query->result() as $row) {
if ($row->members_id > 1) {
echo $row->members_id . "</br>";
}
if ($this->isadvanced($row->members_id, $row->members_direct_id)) {
$this->insert_to_right($row, $row->members_direct_id);
} else {
$this->insert_to_left($row, $row->members_direct_id);
}
}
}
推荐答案
使用codeigniter时,最好建议您仅在视图中 echo
。在任何地方随机显示都会向浏览器发送一些数据,之后,您将无法修改标头(包括尝试重定向,设置内容类型等)
Echoing anywhere randomly sends some data to browser, after which you can't modify headers (this includes attempt to redirect, set content-type, etc)
您应该重新组织代码,例如 echo
仅在视图内完成。这将解决您在Codeigniter中的标头问题。
You should re-organize your code, such that, echo
are done within views only. This will solve your header issues in Codeigniter.
这也包括在大括号 }?> $之后的空格。 c $ c>在非视图php文件中。
This also includes extra whitespaces at the end after the closing brace "} ?>
" in non-view php files.
这篇关于Codeigniter错误消息无法修改标头信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!