Ecco un esempio quick'n'dirty per voi a giocare con e di adeguarsi alle vostre esigenze:
Nel vostro controller:
public $components = array('RequestHandler');
public function sitemap()
{
Configure::write('debug', 0);
$articles = $this->Article->getSitemapInformation();
$this->set(compact('articles'));
$this->RequestHandler->respondAs('xml');
}
Il tuo "articolo" modello:
public function getSitemapInformation()
{
return $this->find('all', array(/* your query here */));
}
View:
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php foreach ($articles as $article): ?>
<url>
<loc><?php echo Router::url(/* generate the URLs here */); ?></loc>
<lastmod><?php echo $time->toAtom(/* last update time here */); ?></lastmod>
<changefreq>weekly</changefreq>
</url>
<?php endforeach; ?>
</urlset>
fonte
2010-09-25 17:54:29
grazie per esempi – meotimdihia
Ricordare di aggiungere public '$ components = array (' RequestHandler ');' nel proprio controller (o AppController.php per l'accesso a tutto l'app) affinché funzioni. – Coreus
@Coreus Ho aggiornato la risposta, grazie! –