2014-10-09 71 views
1

我是Zend Framework 2.3的新手让我们来看看我的应用程序在Zend框架2.3中有多个模块,但我不想为路由模块配置创建单独的文件,我想创建动态路由,那么我该如何执行它帮帮我。我想为zend framework 2.3中的所有模块创建动态路由?

+0

http://stackoverflow.com/questions/20771663/php-zend-framework-2-routing-with-dynamic-controller-name-的重复但是相同控制器 – 2014-10-09 08:03:29

+0

通配符路由被认为是不好的做法。建议使用显式路径代替 – Xerkus 2014-10-09 09:56:59

+0

在zend骨架应用程序中查看此路由,但请记住它不是建议的方法:https://github.com/zendframework/ZendSkeletonApplication/blob/master/module/Application/config/ module.config.php#L23 – Xerkus 2014-10-09 10:07:50

回答

0

一个全球性的路线是你想要什么:

'router' => array(
     'routes' => array(
      'home' => array(
       'type' => 'Zend\Mvc\Router\Http\Segment', 
       'options' => array(
        'route' => '/', 
        'defaults' => array(
         'controller' => 'Application\Controller\Index', 
        ), 
       ), 
      ), 
      'pages' => array(
       'type' => 'Zend\Mvc\Router\Http\Segment', 
       'options' => array(
        'route'  => '/:module/[:controller[/:action[/:id]]]', 
        'constraints' => array(

         'module' => '[a-zA-Z][a-zA-Z0-9_-]*', 
         'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 
         'action' => '[a-zA-Z][a-zA-Z0-9_-]*', 
         'id'   => '[a-zA-Z0-9_-]*' 
        ), 


       ), 
      ), 

    ), 
), 
+0

Zf2应用程序在引导时没有模块的概念。 – Xerkus 2014-10-09 10:00:12

+0

@Xerkus无关紧要,只要控制器具有唯一的名称即可 – Exlord 2014-10-11 06:34:35