自定义Zend Framework 2路由器

时间:2013-01-02 16:17:18

标签: zend-framework2 router

我已经使用zend framework 2开始了应用程序开发。 例如,我将模块命名为' Album'。

我在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 /专辑/专辑/索引

我喜欢路由网址' ZF2 /相册/相册/视图'进入ZF2 / view-album。

我如何路线?帮我。 感谢。

1 个答案:

答案 0 :(得分: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(
                            ),
                        ),
                    ),
                ),
            ),