简体   繁体   English

Zend_Navigation网站地图未生成

[英]Zend_Navigation Sitemap not generating

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. 我目前正在使用Zend Framework 1.12创建项目管理系统,但Zend_Navigation::Sitemap()方法遇到问题。

I have a controller named SitemapController with indexAction() inside it who disable the layout. 我有一个名为SitemapController的控制器, SitemapController带有indexAction() ,它禁用了布局。 Then, my /views/scripts/sitemap/index.phtml script render the sitemap. 然后,我的/views/scripts/sitemap/index.phtml脚本渲染站点地图。

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. 这就是我在/sitemap URI中获得的所有内容。 Even if my navigation.xml is filled. 即使我的navigation.xml已满。

Here's all my code: 这是我所有的代码:

index.phtml index.phtml

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

SitemapController.php 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 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 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? 有人可以告诉我为什么它不按预期方式渲染站点地图吗?

Is there any way to change the encoding in Zend_Navigation? 有什么方法可以更改Zend_Navigation中的编码吗?

I'd suggest to check encoding while you are constructing the menu tree or from your navigation.xml, perhaps. 我建议您在构造菜单树时或从navigation.xml中检查编码。

From Zend_Navigation documentation 从Zend_Navigation文档中

Note UTF-8 encoding used by default 注意默认情况下使用的UTF-8编码

By default, Zend Framework uses UTF-8 as its default encoding, and, specific to this case, Zend\\View does as well. 默认情况下,Zend Framework使用UTF-8作为其默认编码,对于这种情况,Zend \\ View也是如此。 Character encoding can be set differently on the view object itself using the setEncoding() method (or the the encoding instantiation parameter). 可以使用setEncoding()方法(或encoding实例化参数)对视图对象本身进行不同的字符编码设置。 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. 但是,由于Zend \\ View \\ Interface并未定义用于编码的访问器,因此,如果您在Dojo视图助手中使用自定义视图实现,则可能没有getEncoding()方法,该方法是视图助手在内部使用的方法用于确定要编码的字符集。

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. 如果您不想在这种情况下使用UTF-8,则需要在自定义视图实现中实现getEncoding()方法。

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. 在处理ISO-8859-1和JSON时,有时会发生这种情况,它只是剪切输出,对我来说可能是您的语言所致。

UPDATE UPDATE

This is the code I'm using in my sitemapAction : 这是我在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();
}

Based on @Saul Martínez answer, I have written code to generate sitemap. 基于@SaulMartínez的回答,我编写了代码来生成站点地图。 It is not using any XML file but the links can be populated from database. 它没有使用任何XML文件,但是可以从数据库中填充链接。 Here is the link: 链接在这里:

Zend_Navigation overwrite with array? Zend_Navigation是否覆盖数组?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM