2010-02-11 71 views
2

我正在關注用於在CakePHP中創建自動站點地圖的this tutorial。一切都很簡單,但我無法輸出XML。控制器看起來像CakePHP中的自動站點地圖

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'; 
} 

所以它使用的佈局應用程序/視圖/佈局/ XML/default.thtml中

的問題是,我不知道擺在佈局文件是什麼,並在沒有任何跡象表明教程。如果我把

<?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解析器會抱怨。什麼是正確的方式?

+0

鏈接「本教程」不起作用。請考慮並編輯正確的鏈接。 thnks – Meer 2014-11-15 13:05:34

回答

3

我剛碰到你的問題,很遺憾看到它沒有答案。所以讓我們試試看。

在你的控制器中,你已經有$this->RequestHandler->respondAs('xml');,所以根據this comment,它應該足夠了。你有沒有嘗試刪除佈局空白?

此外,您應該有var $components = array('RequestHandler');在您的站點地圖控制器或您的app_controller的某個點。