Whenever I output an xml file, I always get 9 blank lines of whitespace at 开发者_Python百科the top, anyone know what the problem is? I also get a timestamp at the end which I don't want:
<!-- 0.35s -->
Here's the error:
XML Parsing Error: XML or text declaration not at start of entity
Location: http://example.com/controller/get
Line Number 9, Column 1:<?xml version="1.0" encoding="UTF-8" ?>
I put $this->RequestHandler->setContent('xml','text/xml');
in my controller's beforeFilter()
, and the view looks like this:
<?php echo $xml->serialize($data); ?>
while the layout looks like this:
<?php
header("content-type: text/xml");
echo $this->Xml->header();
echo $content_for_layout;
?>
Any ideas? Thanks.
You can also set Configure::write('debug', 0); into controllers beforeFilter() or any other method/serviceCall before rendering to get rid of the timestamp.
The 9 blank lines are probably because you have lines with whitespace at the end of some of the php files in your project. This has caught me out several times in CakePHP.
For a simple way to remove blank lines at the end of all your php files, see this post: Find all files with Blank or WS at BOF or EOF
The timestamp is appended in app/webroot/index.php
, so you can remove it by editing this file (you find the respective code at the end of the file).
精彩评论