I created a sitemap.xml file and saved it in app / webroot /, and this is a file that I can view from a browser like example.com/sitemap.xml . I created a sitemap function in controller , where I get the data from the database and go to view/listings/sitemap.ctp . I also added Router::connect to the app / config / routes.php file.
Is the problem that the data does not appear in example.com/sitemap.xml?
List Manager File:
var $name = 'Listings'; var $components = array('RequestHandler'); public function sitemap(){ $this->layout='ajax'; $this->RequestHandler->respondAs('xml'); $listData = $this->Listing- >find('all',array('conditions'=>array('Listings.status'=>1) ,'order'=> array('Listings.created'=>'Desc'))); $this->set(compact('listData')); }
Sitemap.ctp file:
<?php App::uses('CakeTime', 'Utility'); ?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc><?php echo $html->link('/',true); ?></loc> <changefreq>weekly</changefreq> </url> <?php foreach ($listData as $list){ ?> <url> <loc><?php echo $html->link(array('controller' => 'listings', 'action' => 'sitemap',$list['listings']['id']),true); ?></loc> <lastmod><?php echo $this->Time->toAtom($list['listings']['created']); ? ></lastmod> <changefreq>weekly</changefreq> </url> <?php } ?> </urlset>
File Routes.php:
Router::connect('/sitemap.xml',array('controller' => 'listings', 'action' => 'sitemap', 'ext'=>'xml')); Router::parseExtensions('xml');
When I try to access / listings / sitemap in a browser, an error message appears:

php cakephp sitemap
Farhan dharsi
source share