2013-01-02 39 views
0

我已經開始使用zend框架2開發應用程序。 例如,我將Module命名爲'Album'。自定義Zend Framework 2路由器

而我在module.config.php中有以下代碼。

return array(
    'router' => array(
     'routes' => array(

      'home' => array(
       'type' => 'Zend\Mvc\Router\Http\Literal', 
       'options' => array(
        'route' => '/', 
        'defaults' => array(
         'controller' => 'Album\Controller\Index', 
         'action'  => 'index', 
        ), 
       ), 
      ), 
      'album' => array(
       'type' => 'Segment', 
       'options' => array(
        'route' => '/album', 
        'constraints' => array(
         'action' => '[a-zA-Z][a-zA-Z0-9_-]*', 
         'id'  => '[0-9]+', 
        ), 
        'defaults' => array(
         '__NAMESPACE__' => 'Album\Controller', 
         'controller' => 'Index', 
         'action'  => 'index', 
        ), 
       ), 
       'may_terminate' => true, 
       'child_routes' => array(
        'default' => array(
         'type' => 'Segment', 
         'options' => array(
          'route' => '/[:controller[/:action[/:id]]]', 
          'constraints' => array(
           'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 
           'action'  => '[a-zA-Z][a-zA-Z0-9_-]*', 
           'id'  => '[0-9]+', 
          ), 
          'defaults' => array(
          ), 
         ), 
        ), 
       ), 
      ), 
     ), 
    ), 
); 

我可以訪問以下網址。

ZF2 /專輯 ZF2 /專輯/專輯/索引

我喜歡路線的URL 'ZF2 /專輯/專輯/視圖' 變成ZF2 /視圖專輯。

我該如何路線?幫我。 謝謝。

+0

我得到了解決方案。 – 2plus

回答

0

我用下面的代碼獲得了訪問權限。

'view-album' => array(
       'type' => 'Segment', 
       'options' => array(
        'route' => '/view-album[/:id]', 
        'constraints' => array(
         'action' => '[a-zA-Z][a-zA-Z0-9_-]*', 
         'id'  => '[0-9]+', 
        ), 
        'defaults' => array(
         '__NAMESPACE__' => 'Album\Controller', 
         'controller' => 'Index', 
         'action'  => 'view-album', 
        ), 
       ), 
       'may_terminate' => true, 
       'child_routes' => array(
        'default' => array(
         'type' => 'Segment', 
         'options' => array(
          'route' => '/[:controller[/:action[/:id]]]', 
          'constraints' => array(
           'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 
           'action'  => '[a-zA-Z][a-zA-Z0-9_-]*', 
           'id'  => '[0-9]+', 
          ), 
          'defaults' => array(
          ), 
         ), 
        ), 
       ), 
      ), 
+0

我可以從視圖相冊網址獲取ID。 – 2plus

+0

當我使用:'http:// www.example.com /Formación'時,它不工作,因爲控制器是靜態的'Formación'。我該如何解決它? – YumYumYum