标题已经在CakePHP应用程序中发送错误 [英] Headers already sent error in CakePHP app

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

问题描述

            function new_photo()
            {

                if( !empty($this->data))
                {
                        $this->data['Photo']['showcase_id'] = $this->Session->read('CurrShowcase.id');
                        $this->data['Photo']['added'] = date("Y-m-d H:i:s");
                        $this->Showcase->Photo->save($this->data);

                        $flasher = 'Photo uploaded successfully';
                        $flasher .= '<br/><img src="' . $this->data['Photo']['thumbnail_url'] . '"/>';
                        $this->Session->setFlash($flasher);
                        //$this->redirect(array('action'=>'sc',));
                }
            }   



我在CakePHP应用程序中有一个Showcase Controller,新的照片表单提交新照片。每当我取消注释数据保存后重定向的最后一行,我会收到此错误:

I have a Showcase Controller in my CakePHP app, and a new photo form to submit new photos. Whenever I uncomment the last line that redirects after the data is saved, I get this error:

Warning (2): Cannot modify header information - headers already
sent by (output started at D:\.....

即使我得到这个错误,$ this->数据仍然正确保存在数据库中。但是,如果我注释重定向行如上所示,一切工作正常和无错误。我已检查

Even if I get this error, $this->data still gets saved properly in the database. However, if I comment the redirect line as shown above, everything works fine and error-free. I HAVE checked for blank spaces around the tags, so I'm pretty sure it's not that.

任何想法?

编辑:
注释掉setFlash语句无法解决问题。

commenting out the setFlash statement does not fix the problem.

推荐答案

p>将您的调试模式更改为0,以确保它不是在重定向之前生成的通知/警告。此外,您可能希望收紧处理部分(是偏执的,并且确保它不使用无效索引,因为以及任何其他地方的整个应用程序流程的动作,以确保你没有得到任何输出(如果它的工作原理,当你改变调试为0)。

Change your debug mode to 0 to make sure it's not a notice/warning being generated prior to the redirect. Also, you might want to tighten up your processing section to (be paranoid and) ensure that it's not using invalid indexes, as well as anywhere else throughout the application flow for that action to make sure you're not getting any ouput (if it works when you change debug to 0).

这篇关于标题已经在CakePHP应用程序中发送错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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