doutui8842 2012-10-11 08:12
浏览 58
已采纳

Zend_Navigation Sitemap没有生成

I'm currently creating a project management system with the Zend Framework 1.12 and I got a problem with the Zend_Navigation::Sitemap() method.

I have a controller named SitemapController with indexAction() inside it who disable the layout. Then, my /views/scripts/sitemap/index.phtml script render the sitemap.

Problem, is that:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"/>

It's all I get in the /sitemap URI. Even if my navigation.xml is filled.

Here's all my code:

index.phtml

<?php
$this->navigation()->sitemap()->setFormatOutput(true)
                              ->setUseSchemaValidation(false)
                              ->setUseXmlDeclaration(true)
                              ->setUseSitemapValidators(true);
echo $this->navigation()->sitemap()->render($this->navigation);
?>

SitemapController.php

<?php
class SitemapController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $this->view->layout()->disableLayout();
    }
}

Bootstrap.php

/**
* @return Zend_Navigation
*/
protected function _initNavigation()
{
    $view = $this->bootstrap('layout')->getResource('layout')->getView();
    $config = new Zend_Config_Xml(APPLICATION_PATH.'/configs/navigation.xml', 'nav');
    $navigation = new Zend_Navigation($config);
    $view->navigation($navigation);
}

navigation.xml

<?xml version="1.0" encoding="UTF-8"?>
<configdata>
    <nav>
        <home>
            <label>Tableau de Bord</label>
            <controller>index</controller>
            <action>index</action>
        </home>
        <project>
            <label>Projets</label>
            <controller>project</controller>
            <action>index</action>
        </project>
        <tasks>
            <label>Tâches</label>
            <controller>tasks</controller>
            <action>index</action>
        </tasks>
        <messages>
            <label>Messages</label>
            <controller>messages</controller>
            <action>index</action>
        </messages>
    </nav>
</configdata>

Can someone tell me why it doesn't render the sitemap as it supposed to?

  • 写回答

2条回答 默认 最新

  • doulu5717 2012-10-17 05:13
    关注

    Is there any way to change the encoding in Zend_Navigation?

    I'd suggest to check encoding while you are constructing the menu tree or from your navigation.xml, perhaps.

    From Zend_Navigation documentation

    Note UTF-8 encoding used by default

    By default, Zend Framework uses UTF-8 as its default encoding, and, specific to this case, Zend\View does as well. Character encoding can be set differently on the view object itself using the setEncoding() method (or the the encoding instantiation parameter). However, since Zend\View\Interface does not define accessors for encoding, it’s possible that if you are using a custom view implementation with the Dojo view helper, you will not have a getEncoding() method, which is what the view helper uses internally for determining the character set in which to encode.

    If you do not want to utilize UTF-8 in such a situation, you will need to implement a getEncoding() method in your custom view implementation.

    It sometimes happens to me when dealing with ISO-8859-1 and JSON, that it just cuts the output, it occurs to me that might be something with your language.

    UPDATE

    This is the code I'm using in my sitemapAction:

    /**
     * Shows the site map.
     *
     * @return string
     */
    public function sitemapAction()
    {
        $this->view->layout()->disableLayout();
        $config = new Zend_Config_Xml(APPLICATION_PATH . DS . 'configs' . DS . 'navigation.xml', 'mainnav');
        $container = new Zend_Navigation($config);
        $this->view->navigation($container);
        $this->_helper->viewRenderer->setNoRender(true);
        $response = $this->getResponse();
        $response->setHeader('Content-Type', 'text/xml');
        echo $this->view->navigation()->sitemap();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示