2012-10-21 16 views
3

如何在zf2中編寫允許zf1中的/:controller/:action/*等路由的路由?如何在ZF2中編寫一個滿足GET參數要求的路線?

如此才能滿足像controller/action/id/1/page/2controller/action?id=1&page=2參數?

一條迎合參數的路線,如controller/action?id=1&page=2世界對於ajax請求很有用。

所以我當前的代碼看起來像這樣在我module.config.php

return array(
'controllers' => array(
    'invokables' => array(
     'Support\Controller\Support' => 'Support\Controller\SupportController', 
    ), 
), 

'router' => array(
    'routes' => array(
     'support' => array(
      'type' => 'segment', 
      'options' => array(
       'route' => '/support[/:action][/:id]', 
       'constraints' => array(
        'action' => '[a-zA-Z][a-zA-Z0-9_-]*', 
        'id'  => '[0-9]+', 
       ), 
       'defaults' => array(
        'controller' => 'Support\Controller\Support', 
        'action'  => 'index', 
       ), 
      ), 
     ), 
    ), 
), 
'view_manager' => array(
    'template_path_stack' => array(
     'support' => __DIR__ . '/../view', 
    ), 
), 

回答

0

一看文檔的Zend\Mvc\Router和快速根圍在module.config.php文件在Zend Skeleton Application應用模塊告訴我,你需要設置一個route segment路由器,它將匹配你想創建的url。

除了Zend Framework文檔,還有這個幻燈片放映introduction to routing in Zend Framework,您可能會發現它很有用。它具有你想要實現的代碼示例。

+0

非常感謝您的回覆。我將我的應用程序從「骨架應用程序」中刪除,並閱讀了您提供的幻燈片演示鏈接。它確實表示它支持可選分段(文字和參數部分)的分段路由。 我只是不太確定如何。也許我錯過了一些基本的東西。 – Kenneth

相關問題