ZF2在不使用路由器的情况下运行应用程序

时间:2013-05-28 06:51:18

标签: php zend-framework zend-framework2

我正在学习ZF2。

是否可以在Zf1中运行没有路由器的应用程序? 我们需要为每个控制器定义路由器吗?

示例:

在ZF1中:"admin/index/index"显示为"module/controller/action"

在ZF2中:"admin/index/index"显示为"router[/:controller][/:action]"

请帮我澄清疑惑。

1 个答案:

答案 0 :(得分:0)

请发送这个

return array(
    // routes
    'router' => array(
        'routes' => array(
            'album' => array(
                'type'    => 'Literal',
                'options' => array(
                    'route'    => '/album',
                    'defaults' => array(
                        'controller'    => 'album\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(
                                 // add the default namespace for :controllers in this route
                                 '__NAMESPACE__' => 'album\Controller',
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),    
    'controllers' => array(
        'invokables' => array(
            'album\Controller\Test' => 'Album\Controller\TestController',
        ),
    ),

    'view_manager' => array(
        'template_path_stack' => array(
            'album' => __DIR__ . '/../view',
        ),
    ),
);

您需要手动在invokables中添加控制器名称或通过Abstract Factories

调用
'controllers' => array(
   'invokables' => array(
      'album\Controller\Test' => 'Album\Controller\TestController',
   ),
),

Automatic Controller Invokables via Abstract Factories

Reference