Php FOSRestBundle和symfony2的修补/放置错误

Php FOSRestBundle和symfony2的修补/放置错误,php,symfony,fosrestbundle,Php,Symfony,Fosrestbundle,我需要用symfony2创建一个restapi。没有UI,没有表单,只有RESTAPI 我试图创建一个简单的CRUD系统,但我在更新时遇到了问题 那么 config.yml fos_rest: param_fetcher_listener: force routing_loader: default_format: json # All responses should be JSON formated

我需要用symfony2创建一个restapi。没有UI,没有表单,只有RESTAPI

我试图创建一个简单的CRUD系统,但我在更新时遇到了问题

那么

config.yml

fos_rest:
    param_fetcher_listener: force
    routing_loader:
        default_format: json                            # All responses should be JSON formated
        include_format: false
    exception:
        enabled: true 
FeatureController:

<?php

namespace AppBundle\Controller;

use AppBundle\Entity\Feature;

use FOS\RestBundle\Controller\Annotations;
use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\Request\ParamFetcher;
use Guzzle\Http\Message\Request;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use FOS\RestBundle\Controller\Annotations\RouteResource;
use FOS\RestBundle\Controller\Annotations\RequestParam;
use FOS\RestBundle\Controller\Annotations\QueryParam;
use FOS\RestBundle\View\View;

/**
 * @RouteResource("Feature", pluralize=false)
 */
class FeatureController extends FOSRestController
{
    /**
     * @param ParamFetcher $params
     * @RequestParam(name="type", requirements="[0-9]", default="0", description="type")
     * @RequestParam(name="name", requirements="[a-z]+", description="name")
     *
     * @return array
     */
    public function postAction(ParamFetcher $params){
        $feature = new Feature();
        $feature
            ->setType($params->get('type'))
            ->setName($params->get('name'));

        $em = $this->getDoctrine()->getManager();
        $em->persist($feature);
        $em->flush();

        $view = View::create();
        $view->setStatusCode(201);
        return $this->handleView($view);
    }

    /**
     * @param $id
     * @param ParamFetcher $paramFetcher
     * @RequestParam(name="type", requirements="[0-9]", default="0", description="type")
     * @RequestParam(name="name", requirements="[a-z]+", description="name")
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function patchAction($id, ParamFetcher $paramFetcher){

        $view = View::create();
        $view
            ->setStatusCode(200)
            ->setData([$id, 'params' => $paramFetcher->all()]);
        return $this->handleView($view);
    }

    /**
     * @param $id
     * @param ParamFetcher $paramFetcher
     * @QueryParam(name="page", requirements="\d+", description="Page of the overview.")
     * 
     * @return Response
     */
    public function getAction($id, ParamFetcher $paramFetcher){

        $view = View::create();
        $view->setData(['id' => $id, 'params' => $paramFetcher->all()])->setStatusCode(200);
        return $this->handleView($view);
    }
}
$id,paramefetcher$paramefetcher工作正常

当我将postAction与/feature和body一起使用时

{
  "type" : 2,
  "name" : "aze"
}
它也很好用

但是当我尝试将patchAction与/feature/5和body一起使用时 { “类型”:5, “名称”:“新名称” }

答复是:

{
  "code": 400,
  "message": "Parameter type value '' violated a constraint (This value should not be null.)"
}
你有主意吗


PS:这是我第一次使用FOSRestBundle,如果您有一些最佳做法,请不要犹豫。

您是如何打电话的?和邮递员一起?我记得在使用邮递员和补丁请求时遇到了问题。尝试在您的查询字符串中添加
\u method=patch
,使用postman中的
post
请求模拟
patch
call您可以在patch函数中提供paramefetcher->all()的变量转储吗?
{
  "code": 400,
  "message": "Parameter type value '' violated a constraint (This value should not be null.)"
}