I need to automatic generate sitemaps by using CakePHP. I followed this tutorial: http://designaeon.com/blog/2012/07/cakephp-xml-sitemap-generation/ step by step, but my http://mysite123.com/sitemap.xml only shows me following error:
This page contains the following errors:
error on line 2 at column 6: XML declaration allowed only at the start of the document Below is a rendering of the page up to the first error.
My code looks like this:
Controller/SitemapsController.php:
<?php
class SitemapsController extends AppController{
var $name = 'Sitemaps';
var $uses = array('Video');
function index(){
$this->set('videos', $this->Video->find('all'));
Configure::write ('debug', 0);
}
}
?>
View/Sitemaps/xml/index.ctp:
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php foreach ($videos as $vid): ?>
<url>
<loc><?php echo Router::url('/',true); ?>post/
<?php echo $vid['Video']['id'];?></loc>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
<?php endforeach; ?>
</urlset>
View/Layouts/xml/default.ctp:
<?php header('Content-type: text/xml'); ?>
<?php echo $content_for_layout; ?>
routes.php:
Router::parseExtensions('xml');
Router::connect('/sitemap', array('controller' => 'sitemaps', 'action' => 'index'));
Could you please help me?