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 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 qgcomp混合物线性模型分析的代码出现错误:Model aliasing occurred
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥15 小红薯封设备能解决的来
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答