CakePHP中的自动站点地图

CakePHP中的自动站点地图,php,xml,cakephp,sitemap,Php,Xml,Cakephp,Sitemap,下面我将介绍如何使用CakePHP创建自动站点地图。一切都很简单,但我无法输出XML。控制器看起来像 function sitemap () { Configure::write ('debug', 0); $cats = $this->Category->find('all', array('fields' => array('nicename', 'modified')), null, -1); $posts = $this->Post->

下面我将介绍如何使用CakePHP创建自动站点地图。一切都很简单,但我无法输出XML。控制器看起来像

function sitemap ()
{
    Configure::write ('debug', 0);
    $cats = $this->Category->find('all', array('fields' => array('nicename', 'modified')), null, -1);
    $posts = $this->Post->find('all', array('fields' => array('name', 'modified')), null, -1);
    $this->set(compact('cats','posts'));
    $this->RequestHandler->respondAs('xml');
    $this->viewPath .= '/xml';
    $this->layoutPath = 'xml';
}
因此它使用layout app/views/layouts/xml/default.ctp

问题是我不知道该在布局文件中放置什么,在教程中也没有指示。如果我把

<?php
    echo '<?xml version="1.0" encoding="UTF-8"?>'. "\n";
    echo $content_for_layout;
?>
<?xml version="1.0" encoding="UTF-8"?>
<?php echo $content_for_layout; ?>

我以正确的格式获取一个文件,但作为文本。如果我把

<?php
    echo '<?xml version="1.0" encoding="UTF-8"?>'. "\n";
    echo $content_for_layout;
?>
<?xml version="1.0" encoding="UTF-8"?>
<?php echo $content_for_layout; ?>


我获得了一个XML文件(在Firefox中显示方式不同),但完全为空,因此XML解析器会抱怨。什么是正确的方法?

我刚刚偶然发现了你的问题,看到没有得到回答,我很难过。所以让我们试试看

在您的控制器中已经有
$this->RequestHandler->respondAs('xml')所以根据我们的经验,应该足够了。你有没有试着把版面留白

另外,您应该有
var$components=array('RequestHandler')在站点地图控制器或应用程序控制器中的某个点。

链接“本教程”不起作用。请以正确的链接考虑和编辑。thnks