如何为管理员和客户端制作导航? 是否有一些值可以在下面的代码中添加,比如' id'或其他什么?
代码:
'navigation' => [
'default' => [
[
'label' => 'User',
'route' => 'user',
'pages' => [
[
'label' => 'Login',
'route' => 'user/login',
'action' => 'login',
],
[
'label' => 'Logout',
'route' => 'user/logout',
'action' => 'logout',
],
],
],
],
]
答案 0 :(得分:0)
发现它!
'navigation' => [
'default' => [
[
'label' => 'Blog',
'route' => 'blog',
'pages' => [
[
'label' => 'Detail',
'route' => 'blog/detail',
'action' => 'detail',
],
[
'label' => 'Add',
'route' => 'blog/add',
'action' => 'add',
],
[
'label' => 'Edit',
'route' => 'blog/edit',
'action' => 'edit',
],
[
'label' => 'Delete',
'route' => 'blog/delete',
'action' => 'delete',
],
],
],
],
'navigation-admin' => [
[
'label' => 'Blog',
'route' => 'blog',
'pages' => [
[
'label' => 'Detail',
'route' => 'blog/detail',
'action' => 'detail',
],
[
'label' => 'Add',
'route' => 'blog/add',
'action' => 'add',
],
[
'label' => 'Edit',
'route' => 'blog/edit',
'action' => 'edit',
],
[
'label' => 'Delete',
'route' => 'blog/delete',
'action' => 'delete',
],
],
],
],
]
然后你添加:
'service_manager' => [
'factories' => [
'navigation-admin' => Service\Factory\NavigationFactory::class ]
],
创建扩展Zend \ Navigation \ Service \ DefaultNavigationFactory的工厂类NavigationFactory:
protected function getName()
{
return 'navigation-admin';
}
在视图中,只需检查用户是什么并加载导航:
<?= $this->navigation('navigation-admin')
->menu()
->setMinDepth(0)
->setMaxDepth(0)
->setUlClass('nav navbar-nav')
?>