我有Mongo和Document。我想创建putMethodAction,他检查填充(在文档 - 名称,bode,其他)并更新他或创建新文档。这里:
/**
* Update existing dream from the submitted data or create a new dream at a specific location.
*
* @ApiDoc(
* resource = true,
* description = "Create/Update single dream",
* parameters={
* {"name"="title", "dataType"="string", "required"=true, "description"="Dream name"},
* {"name"="description", "dataType"="string", "required"=true, "description"="Description about dream"},
* {"name"="phone", "dataType"="integer", "required"=true, "description"="Phone number", "format"="(xxx) xxx xxx xxx"}
* },
* statusCodes = {
* 201 = "Returned when the Page is created",
* 204 = "Returned when successful",
* }
* )
*
*
* @param Request $request the request object
* @param int $id the page id
* @return mixed
*/
public function putDreamAction(Request $request, $id)
{
$data = $request->request->all();
$user = $this->getUser();
$data = $this->get('serializer')->serialize($data, 'json');
$dream = $this->get('serializer')->deserialize($data, 'AppBundle\Document\Dream', 'json');
if (!($dm = $this->get('doctrine.odm.mongodb.document_manager')->getRepository('AppBundle:Dream')->findById($id)))
{
$dm = $this->get('doctrine.odm.mongodb.document_manager');
$dm->persist($dream);
$dm->flush();
$restView = View::create();
$restView->setStatusCode(Codes::HTTP_CREATED);
} else {
$restView = View::create();
$restView->setStatusCode(Codes::HTTP_NO_CONTENT);
}
return $restView;
}
其他 - 什么? 怎么做?
答案 0 :(得分:0)
您可以参考Routing documentation来精确配置控制器。
blog_show:
path: /blog/{slug}
defaults: { _controller: AppBundle:Blog:show }
methods: [GET]
blog_update:
path: /blog/{slug}
defaults: { _controller: AppBundle:Blog:update }
methods: [PUT]
blog_delete:
path: /blog/{slug}
defaults: { _controller: AppBundle:Blog:delete }
methods: [DELETE]
通过注释也可以做同样的事情。您还可以传递magic _method
查询参数,该参数应覆盖HTTP方法(请参阅相同的文档)