unable to write xml sitemap in cakephp

Chvg

New Member
I followed this tutorial for creating a dynamic sitemap in cakephp. This tutorial was written in 2008 and I (have inherited) am working in a cakephp 1.3 app (I am assuming this tutorial would be valid for 1.3? I've looked at some others that pretty much used the same code from 2009 and 2010.) Apart from the distressing fact that NOT ONE of my queries is producing anything, my output when I navigate to mysite.com/sitemap.xml is this:\[code\]http://www.site.com/ daily 1.0 http://www.site.com/gulf-coast-finest/3 2012-10-01T19:00:00Z weekly 0.9 http://www.site.com/gulf-coast-finest/4 2012-10-01T19:00:00Z weekly 0.9\[/code\]When I 'view source' I get correctly formatted xml (with the exception that I am missing crucial data), like below:\[code\] <?xml version="1.0" encoding="UTF-8" ?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url> <loc>http://www.site.com/</loc> <changefreq>daily</changefreq> <priority>1.0</priority> </url> <!-- posts--> <url> <loc>http://www.site.com/gulf-coast-finest/3</loc> <lastmod>2012-10-01T19:00:00Z</lastmod> <changefreq>weekly</changefreq> <priority>0.9</priority> </url><url> <loc>http://www.site.com/gulf-coast-finest/4</loc> <lastmod>2012-10-01T19:00:00Z</lastmod> <changefreq>weekly</changefreq> <priority>0.9</priority> </url></urlset> .... \[/code\]I am tearing my hair out wondering why there is no whitespace or xml tags unless I view source. Here is the relevant code from my routes file:\[code\]Router::parseExtensions('xml'); Router::connect('/sitemap', array('controller' => 'sitemaps', 'action' => 'index')); \[/code\]my app/views/layouts/xml/default.ctp file:\[code\]<?phpheader("content-type: text/xml");echo $this->Xml->header();echo $content_for_layout;?> \[/code\]my app/views/sitemaps/xml/index.ctp file:\[code\]<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url> <loc><?php echo Router::url('/',true); ?></loc> <changefreq>daily</changefreq> <priority>1.0</priority> </url> <!-- posts--> <?php foreach ($static as $s):?> <url> <loc><?php echo Router::url('/gulf-coast-finest/'.$s['Article']['Article.link_txt'].'/'.$s['Article']['id'],true); ?></loc> <lastmod><?php echo $time->toAtom('2012-10-01 19:00:00'); ?></lastmod> <changefreq>weekly</changefreq> <priority>0.9</priority> </url><?php endforeach; ?></urlset> \[/code\]and my obviously completed messed up controller:\[code\]<?php class SitemapsController extends AppController{ var $name = 'Sitemaps'; var $uses = array('Category', 'Listing', 'Article', 'Location'); var $helpers = array('Time'); var $components = array('RequestHandler'); function beforeFilter() { //debug logs will destroy xml format, make sure were not in drbug mode Configure::write ('debug', 0); }function index (){ $this->RequestHandler->respondAs('xml'); $this->viewPath .= '/xml'; $this->layoutPath = 'xml'; $a=$this->Article->find('all', array('fields'=>array('Article.id', 'Article.link_txt'))); $this->set('static', $a);}} ?> \[/code\]The very important missing data issue is probably suited to another question. The XML file being one line and having no tags visible to humans is not something I'm ok with. I want to know why it's doing this
 
Back
Top