I'm following this tutorial for creating automated sitemaps in CakePHP. Everything is easy, but I'm not able to output XML. The controller looks like
function sitemap ()
{
Configure::write ('debug', 0);
$cats = $this->Category->find('all', array('fields' => array('nicename', 'modified')), null, -1);
$posts = $this->Post->find('all', array('fields' => array('name', 'modified')), null, -1);
$this->set(compact('cats','posts'));
$this->RequestHandler->respondAs('xml');
$this->viewPath .= '/xml';
$this->layoutPath = 'xml';
}
so it uses the layout app/views/layouts/xml/default.ctp
The problem is that I have no clue what to put in the layout file, and in the tutorial there is no indication. If I put
<?php
echo '<?xml version="1.0" encoding="UTF-8"?>'. "\n";
echo $content_for_layout;
?>
I obtain a file in the correct format, but as text. If I put
<?xml version="1.0" encoding="UTF-8"?>
<?php echo $content_for_layout; ?>
I obtain an XML file (it is displayed differently in Firefox) but completely empty, so the XML parser complains. What is the right way?