使用Zend Framework 2 Restful Web服务进行路由
我想通过使用Zend Framework 2(更准确地说是2.1.5)实现RESTful Web服务。如果我访问,我会得到一个404,相应的消息是“rest(解析为无效的控制器类或别名:rest)”。出了什么问题 您可以在我的github存储库中看到我的源代码: 路线定义如下:使用Zend Framework 2 Restful Web服务进行路由,rest,routing,zend-framework2,Rest,Routing,Zend Framework2,我想通过使用Zend Framework 2(更准确地说是2.1.5)实现RESTful Web服务。如果我访问,我会得到一个404,相应的消息是“rest(解析为无效的控制器类或别名:rest)”。出了什么问题 您可以在我的github存储库中看到我的源代码: 路线定义如下: return array( 'router' => array( 'routes' => array( 'rest' => array(
return array(
'router' => array(
'routes' => array(
'rest' => array(
'type' => 'ZendMvcRouterHttpSegment',
'options' => array(
'route' => '/:controller[.:formatter][/:id]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'formatter' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[a-zA-Z0-9_-]*'
),
),
),
'home' => array(
...
您的路由没有定义控制器所属的命名空间,您需要向路由
默认值添加\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
'rest' => array(
'type' => 'ZendMvcRouterHttpSegment',
'options' => array(
'route' => '/:controller[.:formatter][/:id]',
'defaults' => array(
// tell the router which namespace :controller belongs to
'__NAMESPACE__' => 'Application\Controller',
),
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'formatter' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[a-zA-Z0-9_-]*'
),
),
),
您确定类型有效吗
type' => 'ZendMvcRouterHttpSegment',
对此
type' => 'Segment',
在YourModule/Controller
文件夹中是否确实有RestController
类。如果是这样,您是否已将其映射到module.config.php
中controllers
数组的invokables
部分?也就是说,'YourModule\Controller\Rest'=>'YourModule\Controller\RestController',
谢谢,正如您在我的存储库中看到的,我想我已经完成了这两项工作。还有什么建议吗?