1

我将以下数组传递给:

$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结果没有显示actionurl.

换句话说,注册新运动只显示: 注册新运动

因此它们始终采用以下形式:/module/controller 例如。管理员/用户

4

1 回答 1

2

如果您注册了多个路由,您可能希望包含渲染 url 时使用的路由名称:

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);
于 2013-11-11T10:15:23.690 回答