动作没有在Zend_Navigation输出中呈现?

时间:2013-11-08 08:38:16

标签: php zend-framework navigation

我将以下数组传递给:

$container = new Zend_Navigation($fullmenu);
                    $this->view->navigation()->setContainer($container);

数组(使用print_r转储):

   Array (
    [0] => Array (
    [label] => menu
    [module] => admin
    [controller] => menu
    [action] => index
    [resource] =>
    [class] => settings hidden-xs hidden-sm
    )
    [1] => Array (
    [label] => Users
    [module] => admin
    [controller] => user
    [action] => index
    [resource] =>
    [pages] => Array (
    [0] => Array (
    [label] => Add User
    [module] => admin
    [controller] => user
    [action] => create
    [resource] => 
    )
    [1] => Array (
    [label] => List Users
    [module] => admin
    [controller] => user
    [action] => list
    [resource] =>
    )
    [2] => Array (
    [label] => Audit Trail
    [module] => admin
    [controller] => user
    [action] => trail
    [resource] =>
    )
    )
    [class] => dropdown-toggle
    )
    [2] => Array (
    [label] => reports
    [module] => admin
    [controller] => reports
    [action] => index
    [resource] =>
    [class] => settings hidden-xs hidden-sm
    )
    [3] => Array (
    [label] => tests
    [module] => admin
    [controller] => tests
    [action] => index
    [resource] =>
    [class] => settings hidden-xs hidden-sm
    )
    [4] => Array (
    [label] => Services
    [module] => admin
    [controller] => services
    [action] => index
    [resource] =>
    [class] => settings hidden-xs hidden-sm
    )
    [5] => Array (
    [label] => sports
    [module] => admin
    [controller] => sports
    [action] => index
    [resource] =>
    [pages] => Array (
    [0] => Array (
    [label] => Register New sports
    [module] => admin
    [controller] => sports
    [action] => register
    [resource] => portal:smme.register
    )
    )
    [class] => dropdown-toggle
    )
    )

但是输出中的菜单未正确呈现,因为href's生成的action未显示在url的{​​{1}}中。

换句话说,注册新体育只显示: Register New sports

所以它们总是以下形式:/ module / controller 例如。管理员/用户

1 个答案:

答案 0 :(得分:2)

如果您注册了多个路线,则可能需要包含渲染网址时使用的路线名称:

function includeRouteName(array $menuItems) {
    return array_map(function($menuItem) {
        if (!empty($menuItem['pages'])) {
            $menuItem['pages'] = includeRouteName($menuItem['pages']);
        }
        return new Zend_Navigation_Page_Mvc($menuItem + array(
            'route' => 'default' // assuming you have a route named 'default'
        ));
    }, $menuItems);
}

$fullmenu = includeRouteName($fullmenu);