FOSRestBundle - POST 运行正常,但使用 PUT/PATCH $request 时为空

Ale*_*sse 5 php symfony fosrestbundle

我正在关注本教程http://welcometothebundle.com/symfony2-rest-api-the-best-way-part-3/然后我添加了一个新实体 Author。

使用 GET、POST 和 DELETE 一切都按预期进行,但是在使用 PUT 或 PATCH 时,我得到以下结果:

[{"message":"An exception occurred while executing 'INSERT INTO Author 
(id, name, password) VALUES (?, ?, ?)' with params [16, null, null]:
\n\nSQLSTATE[23502]: Not null violation: (...)
Run Code Online (Sandbox Code Playgroud)

这是我收到的标题:

Allow ?GET, PUT, PATCH, DELETE
Cache-Control ?no-cache
Connection ?keep-alive
Content-Type ?application/json
Date ?Tue, 28 Oct 2014 14:30:10 GMT
Server ?nginx/1.1.19
Transfer-Encoding ?chunked
X-Debug-Token ?6d899c
X-Debug-Token-Link ?/api/_profiler/6d899c
X-Powered-By ?PHP/5.4.33-2+deb.sury.org~precise+1
Run Code Online (Sandbox Code Playgroud)

这是我的 PHP 代码

public function putAuthorAction(Request $request, $id)
{
    try {
        if (!($author = $this->container->get('acme_blog.author.handler')->get($id))) {
            $statusCode = Codes::HTTP_CREATED;
            $author = $this->container->get('acme_blog.author.handler')->post(
                $request->request->all()
            );
        } else {
            $statusCode = Codes::HTTP_NO_CONTENT;
            $author = $this->container->get('acme_blog.author.handler')->put(
                $author,
                $request->request->all()
            );
        }

        $routeOptions = array(
            'id' => $author->getId(),
            '_format' => $request->get('_format'),
        );

        return $this->routeRedirectView('get_author', $routeOptions, $statusCode);

    } catch (InvalidFormException $exception) {
        return $exception->getForm();
    }
}
Run Code Online (Sandbox Code Playgroud)

然后我插入了一个

return $request->request->all();
Run Code Online (Sandbox Code Playgroud)

在 putAuthorAction 中尝试块之前,我得到一个空数组作为响应...

有没有人有类似的问题?

我已经尝试过这样做FosRestBundle post/put [create new/update entity] 没有正确读取 Request但没有成功..

我在 Chromium 中使用 Postman 扩展来测试......(对不起我的英语,这不是我的主要语言)