ZF2 Skeleton app路由 - 儿童路线

时间:2014-06-24 14:07:10

标签: php routing zend-framework2

我正在尝试基于Zend骨架应用程序在我的应用程序中使用Routing。

我需要以下映射:

localhost / => Aplication / Controller / IndexController => indexAction() - > 这只能起作用
localhost / portfolio / section => Application / Controller / PortfolioController =>的indexAction()
localhost / portfolio / section / action / id => Application / Controller / PortfolioController => specifi_cactionAction()

我有这个(module.config.php):

'router' => array(
    'routes' => array(
        'home' => array(
            'type' => 'Zend\Mvc\Router\Http\Literal',
            'options' => array(
                'route'    => '/',
                'defaults' => array(
                    'controller' => 'Application\Controller\Index',
                    'action'     => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'portfolio' => array(
                    'type' => 'Zend\Mvc\Router\Http\Segment',
                    'options' => array(
                        'route' => '[/portfolio/:section[/:action][/:id]]',
                        'constraints' => array(
                            'section' => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'action'  => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'id'      => '[0-9]+',
                        ),
                        'defaults' => array(
                            '__NAMESPACE__' => 'Application\Controller',
                            'controller'    => 'Portfolio',
                            'action'        => 'index',
                        ),
                    ),
                ),
            )
        ),
    ),
),
'controllers' => array(
    'invokables' => array(
        'Application\Controller\Index'     => 'Application\Controller\IndexController',
        'Application\Controller\Portfolio' => 'Application\Controller\PortfolioController',
    ),
),  

现在,如果我去 localhost / portfolio / graphics / ,我会收到错误:
发生404错误 网页未找到。 路由无法匹配请求的URL。 没有例外

我也尝试过子路线(没有/ on开始):

'route' => '[portfolio/:section[/:action][/:id]]',

我不明白。为什么这不起作用?

0 个答案:

没有答案