我似乎只能在调用/商船/1时才能创建新的实体,但是/merchant将返回405状态。
这是我的职位资源方法:
public function create($data)
{
return $this->mapper->create($data);
}该实体的id是一个auto_incrment字段,因此对我来说,客户机不提供标识符是有意义的。
下面是我的module.config.php的一个片段:
'zf-rest' => array(
'MyTest\\V1\\Rest\\Merchant\\Controller' => array(
'listener' => 'MyTest\\V1\\Rest\\Merchant\\MerchantResource',
'route_name' => 'MyTest.rest.merchant',
'route_identifier_name' => 'merchant_id',
'collection_name' => 'merchant',
'entity_http_methods' => array(
0 => 'GET',
1 => 'PATCH',
2 => 'PUT',
3 => 'POST',
),
'collection_http_methods' => array(
0 => 'GET',
),
'collection_query_whitelist' => array(),
'page_size' => 25,
'page_size_param' => null,
'entity_class' => 'MyTest\\V1\\Rest\\Merchant\\MerchantEntity',
'collection_class' => 'MyTest\\V1\\Rest\\Merchant\\MerchantCollection',
'service_name' => 'Merchant',
),不知道我还能提供什么帮助你们了解情况,但乐意提供更多的细节要求。
耽误您时间,实在对不起。
发布于 2014-06-24 15:20:19
如果您在Restful上创建了一个新资源,那么您将在收集路由上发布一个帖子。因此,应该将POST方法添加到collection_http_methods数组中。这完全符合Restful规范。
'collection_http_methods' => array(
0 => 'GET',
1 => 'POST',
),我想如果你改变了它应该会起作用的。还有一件事,我不知道为什么在文档中这样做,但是我的http_methods数组是这样的:
'collection_http_methods' => array('GET', 'POST')如果你问我:)
发布于 2014-06-08 21:43:47
因此,我添加了POST作为允许的方法,现在它可以用于发布单个实体。
不知道这是故意的还是非故意的,但解决了我的问题。
https://stackoverflow.com/questions/24109602
复制相似问题