我想以适当的xml格式显示我的站点地图,但它显示在一行中:
http://www.example.com/home 1.00 http://www.example.com/about 0.50 http://www.example.com/login 0.20 http://www. etc
不
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
<url>
<loc>http://www.example.com/home</loc>
<priority>1.00</priority>
</url>
<url>
<loc>http://www.example.com/about</loc>
<priority>0.50</priority>
</url>
etc.
我在SitemapController中的代码:
<?php
class SitemapController extends Zend_Controller_Action
{
public function sitemapAction()
{
$this->_helper->layout->disableLayout();
$this->getResponse()->setHeader('Content-Type', 'text/xml; charset=utf-8');
}
}
sitemap.phtml中的代码:
<?php echo '<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
<url>
<loc>http://www.example.com/home</loc>
<priority>1.00</priority>
</url>
<url> etc...
在我的routes.ini中:
resources.router.routes.sitemap.type = "Zend_Controller_Router_Route"
resources.router.routes.sitemap.route = "/sitemap.xml"
resources.router.routes.sitemap.defaults.module = "default"
resources.router.routes.sitemap.defaults.controller = "sitemap"
resources.router.routes.sitemap.defaults.action = "sitemap"
根据之前的问题,控制器中的disableLayout()应该已经完成,但对视图中的实际xml布局没有影响。
答案 0 :(得分:0)
由于您正在设置正确的内容类型,因此听起来这只是您的浏览器选择呈现XML数据的方式。根据您使用的浏览器,您可能希望查看是否可以找到可以为您提供更好的XML格式的扩展程序。