Sitemap XML in Kohana

application\bootstrap.php :

Route::set('sitemap_xml', 'sitemap.xml',
    array())
    ->defaults(array(
        'controller' => 'sitemap',
        'action'     => 'index'
    ));

application\controller\sitemap.php :

<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Sitemap extends Controller {

    public function action_index()
    {
        $oDOMDocument = new DOMDocument('1.0', 'UTF-8');
        $urlset = $oDOMDocument->createElement('urlset');
        $urlset->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
        $oDOMDocument->appendChild($urlset);

        // Static Pages

        $aItems = array(
            array('loc' => '', 'lastmod' => date ("Y-m-d"), 'changefreq' => 'weekly', 'priority' => '1.0'),
            array('loc' => 'contact', 'lastmod' => date ("Y-m-d", filemtime('application/views/content/contact.tpl')), 'changefreq' => 'never', 'priority' => '0.5')
        );

        // @todo Dynamic Pages

        foreach ($aItems as $item)
        {
            $url = $oDOMDocument->createElement('url');
            $loc = $oDOMDocument->createElement('loc', Url::Site().$item['loc']);
            $url->appendChild($loc);

            if ( ! empty($item['lastmod']))
            {
                $lastmod = $oDOMDocument->createElement('lastmod', $item['lastmod']);
                $url->appendChild($lastmod);
            }

            if ( ! empty($item['changefreq']))
            {
                $changefreq = $oDOMDocument->createElement('changefreq', $item['changefreq']);
                $url->appendChild($changefreq);
            }

            if ( ! empty($item['priority']))
            {
                $priority = $oDOMDocument->createElement('priority', $item['priority']);
                $url->appendChild($priority);
            }

            $urlset->appendChild($url);
        }

        $this->request->headers['Content-Type'] = 'application/xml';
        // $this->response->headers('Content-Type', 'application/xml');

        echo $oDOMDocument->saveXML();
    }
}

Zie ook : Sitemap XML