2013-03-20 126 views
1

目前我在玩與Zend導航在ZF2和我在我的應用程序模塊中遇到以下問題ZF2導航與骨架默認路由

我有以下的配置(默認骨架APP)

.... 
'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', 
       ), 
      ), 
     ), 

    ), 
), 
.... 

我目前只能在我爲菜單中的「每個」項目添加路線時才能進行導航工作。但這是一種奇怪的解決方案。

那麼,這是正確的方式來使菜單工作,或者我需要做一些與網頁的幻想嗎?

+0

我真的得到它自己工作:)而不是使用父(應用程序)路線我需要指向它的兒童路線應用程序/默認問題解決 – Ponsjuh 2013-03-20 19:23:09

+0

發佈爲答案;)爲更快的引用其他用戶。 – Sam 2013-03-21 07:54:57

回答

2

其實我得到它的工作我自己:)而不是使用父(應用程序)的路線,我需要把它指向子路線應用/默認的問題就迎刃而解了

這樣的配置現在看起來像

.... 
'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', 
       ), 
      ), 
     ), 

    ), 
), 
....