CakePHP 2.1에서 자동으로 Sitemap을 생성하려고하는데 헤더 응답을 text/xml로 변경했지만 브라우저가 text/html 응답을 받고 있습니다.Xml 헤더가 CakePHP 2.1에서 작동하지 않습니다.
SitemapsController :
<?php
class SitemapsController extends AppController{
var $uses = array('Post');
var $helpers = array('Time');
var $components = array('RequestHandler');
function index(){
Configure::write ('debug', 0);
$this->set('posts', $this->Post->find('all', array('conditions'=>array('publique'=>1))));
$this->RequestHandler->respondAs('xml');
}
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow();
}
public function isAuthorized($user) {
return true;
}
}
?>
/view/Sitemaps/xml/index.ctp
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc><?php echo Router::url('/',true); ?></loc>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
<?php foreach ($posts as $post):?>
<url>
<loc><?php echo Router::url(array('action'=>'view', 'id'=>$post['Post']['id'], 'slug'=>$post['Post']['slug']),true); ?></loc>
<lastmod><?php echo $this->Time->toAtom($post['Post']['created']); ?></lastmod>
<priority>0.8</priority>
</url>
<?php endforeach; ?>
</urlset>
레이아웃/XML/default.ctp
<?php header('Content-type: text/xml'); ?>
<?= $this->fetch('content'); ?>
routes.php
Router::parseExtensions('xml');
Router::connect('/sitemap',array('controller'=>'sitemaps','action'=>'index','url'=>array('ext'=>'xml')));
같은 문제 :(콘텐츠 형식이 –
을 변경하고 컨트롤러 렌더링 지정하지 않는 것처럼 보인다 :. respondAs 후, 줄을 추가 $ this-> RequestHandler-> renderAs ($ this, 'xml'); – ylerjen
requestHandler는 아무 것도 변경하지 않는다 !!, 나는 같은 결과를 얻었거나 만들지 않았다 !! –