【发布时间】:2014-01-24 08:41:42
【问题描述】:
我是 Zend Framework 的新用户,我有一个项目要做。问题是我无法将路由配置到第二个控制器。第一个控制器(索引)运行良好,但不是新控制器。
我使用 zftool 创建了模块,因此我有一个名为“Medicaments”的模块。当我尝试使用以下 url localhost/project_zend/public(或 localhost/project_zend/public/medicaments)访问我的项目时,它可以工作,并且我到达了我的 IndexController,indexAction。但是当我尝试访问我的新控制器“ConfigurationController(存在于 /modules/Medicaments/Controller/)时,我到达了 404 页面,说“请求的控制器无法调度请求。”我的观点表明使用的控制器是“药物/控制器/索引”而不是“药物/控制器/配置”。
这是我的路由器配置(在 /modules/Medicaments/config/module.config.php 中)文件:
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Medicaments\Controller\Index',
'action' => 'index',
),
),
),
'medicaments' => array(
'type' => 'segment',
'options' => array(
'route' => '/medicaments[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'Medicaments\Controller',
'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(
),
),
),
),
),
'configuration' => array(
'type' => 'segment',
'options' => array(
'route' => '/configuration[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Configuration',
'action' => 'index',
),
),
),
),
),
感谢您的帮助。
【问题讨论】:
-
您的网址中无需使用“/public”
标签: zend-framework2