0

我在使用 Zend_Navigation 设置面包屑和菜单时遇到问题。

首先,我使用 XML 配置对象设置我的页面:

<?xml version="1.0" encoding="UTF-8"?>
<configdata>
<nav>
    <home>
        <label>Home</label>
        <controller>Index</controller>
        <action>index</action>
        <id>home</id>
        <resource>default</resource>
    </home>
    <crm>
        <label>CRM</label>
        <module>Crm</module>
        <controller>Index</controller>
        <action>index</action>
        <id>crm</id>
        <resource>Crm</resource>
        <pages>
            <persons>
                <module>Crm</module>
                <label>Personen</label>
                <controller>Persons</controller>
                <action>index</action>
            </persons>
           (...)etc.(...)

然后在我的引导程序中:

//Bootstrap.php
$view = $layout -> getView();
$config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
$navigation = new Zend_Navigation($config);
$view -> navigation($navigation);
$view -> menu = $view -> navigation() -> menu();
$view -> breadcrumbs = $view -> navigation()->breadcrumbs()->setMinDepth(0);

现在,如果我要导航到http://hostname/Crm/Persons/活动状态,那么面包屑也会正确显示。

但是,当我转到http://hostname/Crm/Persons/inspect/id/3(其中检查是操作,id 是参数)时,面包屑将为空,并且所有菜单项都不会处于活动状态。预期的面包屑类似于:Home > CRM > Personen > John并且 CRM 和 Personen 应该在菜单中处于活动状态。

现在 Zend 文档给了我一个线索:它可能因为设置了参数而无法工作。

/*
* Dispatched request:
* - module:     blog
* - controller: post
* - action:     view
*/
$page = new Zend_Navigation_Page_Mvc(array(
    'action'     => 'view',
    'controller' => 'post',
    'module'     => 'blog',
    'params'     => array('id' => null)
));

// returns false, because page requires the id param to be set in the request
$page->isActive(); // returns false

我不知道如何解决这个问题。思想受到高度赞赏。

4

2 回答 2

0

我之前没有使用 xml 文件在 ZF 中设置导航,所以我不确定这是否可行。但根据我的经验,将以下内容添加到您的人物标签中:

    <params>
        <id>0</id>
    </params>

在此示例中,id 默认设置为 0。

看到这个问题

于 2011-06-06T14:32:57.633 回答
0

经过一些(很多)修补后,我发现我需要在 XML 中定义页面,然后 Zend 才能识别结构。

<?xml version="1.0" encoding="UTF-8"?>
<configdata>
<nav>
    <home>
        <label>Home</label>
        <controller>Index</controller>
        <action>index</action>
        <id>home</id>
        <resource>default</resource>
    </home>
    <crm>
        <label>CRM</label>
        <module>Crm</module>
        <controller>Index</controller>
        <action>index</action>
        <id>crm</id>
        <resource>Crm</resource>
        <pages>
            <persons>
                <module>Crm</module>
                <label>Personen</label>
                <controller>Persons</controller>
                <action>index</action>
                <pages>
                    <inspect>  <--- this will make Zend recognize the page
                        <module>Crm</module>
                        <label>Persoon</label>
                        <controller>Persons</controller>
                        <action>inspect</action>
                    </inspect>
                </pages>
            </persons>
            (...)etc(...)

请注意,我不希望检查操作显示在菜单上并将最大渲染深度设置为 1:

$view -> menu = $view -> navigation() -> menu()->setMaxDepth(1);

于 2011-06-07T09:12:42.080 回答