笨错误信息不能更改头信息
当我运行我的PHP CodeIgniter的项目中,我得到这个错误信息:笨错误信息不能更改头信息
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\tree\application\models\mtree.php:17)
Filename: core/Common.php
Line Number: 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
。
呼应随时随地随机发送一些数据到浏览器,之后就不能修改标题(包括尝试重定向,设置内容类型等)
你应该重新组织你的代码,这样, echo
仅在视图内完成。这将解决Codeigniter中的标题问题。
这还包括在非视图php文件中的大括号“} ?>
”后端的额外空格。
是的,这个作品谢谢:-D – Cristiana214
回声只在视图内。 +1 – rachitmanit
在调用标题函数之前,不能显示任何东西。您不应该显示任何表单模型或控制器以避免此类错误。如果要显示控制器或模型的某些内容,则应将输出存储到缓冲区,而不是将其发送到浏览器。在调用header()
函数之前,可以使用ob_start()
函数将输出存储到缓冲区。然后你可以做这样的事情
if(true)
{
header("Location:http://google.com");
}
else
{
ob_end_flush();
}
这是你的问题 - echo $ row-> members_id。 “”; - 如上述回答说,不回应你的控制器的东西,推到这样做的意见 - 始终
我认为这将是有益的 使用而不是$config['sess_save_path'] = NULL;
在Application/config/config.php
文件
无关:您在本声明结尾处缺少引号:* $ this-> db-> query(“INSERT INTO'table1'('members_id','members_username'); * –
将某些内容发送到用户**在调用**之前添加到'header'函数。您提供的代码没有提供足够的信息来帮助调试。阅读更多关于错误的信息:http://php.net/manual/en/function.header.php – adeelx
看看这里http://*.com/questions/8028957/headers-al准备发送的PHP –