我有这样的基本路线设置(只剩下相关部分):
return array(
'controllers' => array(
'invokables' => array(
'Main\Controller\Login' => 'Main\Controller\LoginController',
'Main\Controller\Main' => 'Main\Controller\MainController',
'Main\Controller\Index' => 'Main\Controller\IndexController',
'Main\Controller\Candidate' => 'Main\Controller\CandidateController',
),
),
'router' => array(
'routes' => array(
'home' => array(
'type' => 'literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Main\Controller\Index',
'action' => 'index',
),
),
),
'main' => array(
'type' => 'literal',
'options' => array(
'route' => '/ts',
'defaults' => array(
'controller' => 'Main\Controller\Main',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'candidates' => array(
'type' => 'literal',
'options' => array(
'route' => '/candidate',
'defaults' => array(
'controller' => 'Main\Controller\Candidate',
'action' => 'index'
),
),
'may_terminate' => true,
'child_routes' => array(
'add' => array(
'type' => 'literal',
'options' => array(
'route' => '/add'
),
'defaults' => array(
'action' => 'add'
),
),
),
),
),
),
),
),
所以我相信这些路线是:
/
/ts
/ts/candidate
/ts/candidate/add
除了最后一个,一切都很顺利/ts/candidate/add
我做了一些基本的视图,每个都返回简单
echo '<action_name>'
action_name
控制器的动作在哪里。但是每次,当我进入时/ts/candidate/add
,我index action
从
'Main\Controller\CandidateController'
而不是add action
. 视图结构如下所示:
view
-- errror
-- 404.phtml
-- index.phtml
-- layout
-- layout.phtml
-- login.phtml
-- main
-- candidate
-- index.phtml
-- add.phtml
-- main
-- index.phtml