我的应用程序有一个模块Catalog
,它应该显示三个视图:
/catalog/
%city%
/catalog/%city%
中的体育列表
%sport%
%city%
中/catalog/%city%/%sport%
的课程列表
我的路由选项目前看起来像这样:
<?php
return array(
...
'router' => array(
'routes' => array(
'catalog' => array(
'type' => 'segment',
'options' => array(
'route' => '/catalog[/:city][/:sport][/]',
'constraints' => array(
'city' => '[a-zA-Z][a-zA-Z0-9_-]*',
'sport' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'controller' => 'Catalog\Controller\Catalog',
'action' => 'index',
),
),
),
),
),
...
);
我的CatalogController
:
class CatalogController extends AbstractActionController {
public function indexAction() {
return new ViewModel();
}
public function listCitiesAction() {} // all cities
public function listSportsAction() {} // all sports for the city
public function listCoursesAction() {} // all courses for the sport in the city
}
如何定义路线,以便它映射到上面的动作?
THX
答案 0 :(得分:0)
有效!
'router' => array(
'routes' => array(
'catalog' => array(
'type' => 'literal',
'options' => array(
'route' => '/catalog',
'defaults' => array(
'controller' => 'Catalog\Controller\Catalog',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'city' => array(
'type' => 'segment',
'options' => array(
'route' => '/:city',
'constraints' => array(
'city' => '[a-zA-Z][a-zA-Z0-9_-]*',
'sport' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'controller' => 'Catalog\Controller\Catalog',
'action' => 'list-sports',
),
),
'may_terminate' => true,
'child_routes' => array(
'sport' => array(
'type' => 'segment',
'options' => array(
'route' => '/:sport',
'constraints' => array(
'city' => '[a-zA-Z][a-zA-Z0-9_-]*',
'sport' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'controller' => 'Catalog\Controller\Catalog',
'action' => 'list-courses',
),
),
),
),
),
),
),
),
),