CakePHP – Warning (2): Cannot modify header information

I going through Cake’s 15min Blog Tutorial (again) and I hit a problem after I’d added the add and delete functions to the controller.

My list of blog posts displays fine, clicking on the “Add Post” link from the index works fine – but when I submit the add form I get the following warning:

Warning (2): Cannot modify header information - headers already sent by (output started at /var/www/cake/app/models/post.php:9) [CORE/cake/libs/controller/controller.php, line 644]

I was getting this when I tried to delete a post too.

Turns out that there was extra whitespace after the ?> closing PHP element in my post.php – removing it fixed the problem.

UPDATE: I’ve found a solution to this problem.

Creating Post Views step in cakePHP’s Create A Blog example not working

That’s one helluva post title!

If you’ve got to this step in the Blog Tutorial example application:

http://book.cakephp.org/view/336/Creating-Post-Views

and you get a 404 error when you try to access the suggested URL of http://www.example.com/posts/index then your problem might be that in the “A note on mod_rewrite” page you decided not to use mod_rewrite. If that’s the case you need to use this URL instead:

http://www.example.com/index.php/posts/index