【问题标题】:ZF2 navigation with skeleton default routeZF2 导航带骨架默认路由
【发布时间】:2013-03-20 19:10:52
【问题描述】:

目前我在 ZF2 中使用 Zend Navigation,遇到以下问题

在我的应用程序模块中,我有以下配置(默认骨架应用程序)

....
'router' => array(
    'routes' => array(
        'home' => array(
            'type' => 'Zend\Mvc\Router\Http\Literal',
            'options' => array(
                'route'    => '/',
                'defaults' => array(
                    'controller' => 'Application\Controller\Index',
                    'action'     => 'index',
                ),
            ),
        ),
        // The following is a route to simplify getting started creating
        // new controllers and actions without needing to create a new
        // module. Simply drop new controllers in, and you can access them
        // using the path /application/:controller/:action
        'application' => array(
            'type'    => 'Literal',
            'options' => array(
                'route'    => '/application',
                'defaults' => array(
                    '__NAMESPACE__' => 'Application\Controller',
                    'controller'    => 'Index',
                    'action'        => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'default' => array(
                    'type'    => 'Segment',
                    'options' => array(
                        'route'    => '/[:controller[/:action]]',
                        'constraints' => array(
                            'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                        ),
                        'defaults' => array(
                        ),
                    ),
                ),
            ),
        ),
        'info' => array(
            'type' => 'Zend\Mvc\Router\Http\Literal',
            'options' => array(
                'route'    => '/phpinfo',
                'defaults' => array(
                    'controller' => 'Application\Controller\Index',
                    'action'     => 'info',
                ),
            ),
        ),
    ),
),
....
'navigation' => array(
    'default' => array(
        array(
            'label' => 'Home',
            'route' => 'home',
            'order' => -1,
            'pages' => array(
                array( //<-- this isn't working gives a link to /application
                    'label'         => 'Telefoonboek',
                    'route'         => 'application',
                    'module'        => 'application',
                    'controller'    => 'telefoonboek',
                    'action'        => 'index',
                ),
                array( //<-- this works
                    'label'         => 'Telefoonboek2',
                    'uri'           => '/application/telefoonboek', 
                ),
                array( //<-- this works
                    'label'         => 'info',
                    'route'         => 'info',
                ),
            ),
        ),

    ),
),
....

当我在菜单中为我想要的“每个”项目添加路线时,我目前只能使导航工作。但这是一种奇怪的解决方案。

那么这是使菜单正常工作的正确方法还是我需要对页面做一些花哨的事情?

【问题讨论】:

  • 我实际上让它自己工作 :) 而不是使用父(应用程序)路由,我需要将它指向子路由应用程序/解决的默认问题
  • 将其发布为答案 ;) 以便更快地引用其他用户。

标签: php zend-framework2


【解决方案1】:

我实际上让它自己工作 :) 而不是使用父(应用程序)路由,我需要将它指向子路由应用程序/解决的默认问题

所以配置现在看起来像

   ....
'navigation' => array(
    'default' => array(
        array(
            'label' => 'Home',
            'route' => 'home',
            'order' => -1,
            'pages' => array(
                array( //<-- this NOW works too
                    'label'         => 'Telefoonboek',
                    'route'         => 'application/default',
                    'controller'    => 'telefoonboek',
                    'action'        => 'index',
                ),
                array( //<-- this works
                    'label'         => 'Telefoonboek2',
                    'uri'           => '/application/telefoonboek', 
                ),
                array( //<-- this works
                    'label'         => 'info',
                    'route'         => 'info',
                ),
            ),
        ),

    ),
),
....

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-05
    相关资源
    最近更新 更多