symfony2 FOSRestBundle annotations

前端 未结 2 614
悲哀的现实
悲哀的现实 2021-02-02 03:07

Is anyone used put, get, post, delete annotations(https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Controller/Annotations/) in controller.

I\'m trying to u

2条回答
  •  情话喂你
    2021-02-02 03:16

    You shouldn't put the id in the route (since that's equivalent to a get). Instead you should do this to force the id param to be sent through $_POST

    /**
    * @Route("/get", defaults={"_format" = "json"})
     * @Post
     */
    public function getObject() {  
        $id = $this->Request::createFromGlobals()->request->get('id');
        $object = $this->getService()->findById($id);
        return $object;
    }
    

提交回复
热议问题