Display data from database in sitemap.xml using cakephp 2.0

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:

image

+1
php cakephp sitemap
source share

No one has answered this question yet.

See similar questions:

7
How to create a Sitemap for CakePHP?

or similar:

635
How to pass variables and data from PHP to JavaScript?
2
PHP DOMDocument - how to add a namespace declaration?
one
CakePHP Routing MissingControllerException
0
Cake: Using Relative URLs
0
laravel MVC execution thread
0
cakePHP 2 does not return jsonp
0
CSS file not linked
0
CakePHP - the problem of creating / displaying views
0
CakePHP Creating XML View Files

All Articles