Mongodb API,如何创建Put方法?

Mongodb API,如何创建Put方法?,mongodb,api,rest,symfony,put,Mongodb,Api,Rest,Symfony,Put,我有Mongo和文件。我想创建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",

我有Mongo和文件。我想创建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;

}
还有什么? 怎么做

您可以参考以精确配置控制器

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
\u method
查询参数,该参数应覆盖HTTP方法(参见相同的文档)