1

我有一个以文章为元素的 xml 导航系统。面包屑在我的文章页面上有效,我在其中显示文章列表及其标题(作为链接)和预告段。我显示全文的页面不显示任何面包屑导航。

我知道我做错了什么,但是由于我是zend的新手,所以我不知道在哪里。

如果有人能指出我正确的方向,我将不胜感激。

XML 导航:

<?xml version="1.0" encoding="UTF-8"?>
  <configdata>
  <nav>
    <home>
        <label>Home</label>
        <controller>index</controller>
        <action>index</action>
        <pages>

            <about>
                <label>About</label>
                <controller>index</controller>
                <action>about</action>

            </about>
        <board>
            <label>Executive Committee</label>
            <controller>index</controller>
            <action>committee</action>
        </board>
        <events>
                <label>Events</label>
                <controller>index</controller>
                <action>events</action>
        </events>


        <member>
                <label>CNFS Members</label>
                <controller>index</controller>
                <action>member</action>

            </member>
            <news>
                <label>Blog</label>
                <controller>blog</controller>
                <action>index</action>

            </news>
            <contact>
                <label>Contact</label>
                <controller>index</controller>
                <action>contact</action>
        </contact>
        </pages>
    </home>
</nav>
</configdata>

这是引导文件中用于导航的函数。

<?php
   protected function _initViewNavigation(){
     $this->bootstrap('layout');
     $layout = $this->getResource('layout');
     $view = $layout->getView();
     $config = new Zend_Config_Xml(APPLICATION_PATH.'/configs/navigation.xml','nav');
     $navigation = new Zend_Navigation($config);
     $view->navigation($navigation);
    }
    ?>

这就是我在视图中显示面包屑的方式:

    <?php echo  'Your are here: ' . $this->navigation()->breadcrumbs() ->setMinDepth(0)->setLinkLast(false)->setSeparator("   /  ");?>
4

1 回答 1

1

从您的 xml 中,我猜您的文章列表位于 /blog,而单篇文章位于 /blog/article/'articleId' 或类似的位置。

您导航地图中的“新闻”部分定义了一个操作“索引”,但要显示一篇文章,您使用其他操作,这就是该节点不再匹配的原因。

我猜您希望当前文章的标题显示在面包屑的末尾,为此您必须附加一个自定义页面作为“新闻”节点的子节点,并将其设置为“活动”:

public function articleAction(){
    //get your article
    $article = ....


    $page = new Zend_Navigation_Page_Mvc(array(  
            'label'         => $article->getTitle(),  
            'controller'    => 'blog',  
            'action'        => 'article',  
            'params'        => array(
                'id' => $article->getId() // replace with the param name + value that you actually use in your url
                 )
            )
       );
    $page->setActive(true);

    $this->view->_helper->navigation()->getContainer()->findOneBy('controller','blog')->addPage($page);

我在没有测试的情况下通过内存编写了这段代码,所以如果它没有按预期工作,请告诉我,我会测试并更新这个答案

于 2011-09-22T09:21:41.743 回答