Symfony内容始终为null

时间:2015-06-08 15:39:01

标签: php angularjs rest symfony

我有一个Symfony2项目,但我完全迷失了。我希望能够得到评论。 在我的服务器端,我有:

 /**
 *
 * @Get("/{communeId}/room/{roomId}/booked/time/", requirements={"communeId" : "\d+", "roomId" : "\d+"})
 * @param int     $communeId
 * @param int     $roomId
 * @param Request $request
 *
 * @ApiDoc(
 *  resource=false,
 *  description="See if room is available",
 *  statusCodes={
 *         204="Returned when deleted successfully",
 *         401="Returned when you are not authorized",
 *  },
 * )
 *
 * @Rest\View()
 *
 *
 * @return View
 */
public function getRoomBookingAvailableAction($communeId, $roomId, Request $request)
{
    $data = json_decode($request->getContent(), true)['comment'];
    return View::create()
        ->setStatusCode(200)
        ->setData($data)
        ->setSerializationContext(
            SerializationContext::create()
                ->enableMaxDepthChecks()
                ->setGroups(array("detail", "commune", "reservationItemDetail"))
        );
}

在客户端,我有:

//Refresh the current booking, check for exclusiondates and handle errors
$scope.refreshBooking = function () {
  API.get('api/v1/booking/' + $scope.bookingId).success(function (response) {
    $scope.booking = response;
    $scope.multiply($scope.booking.exclusionDates);
    $scope.dayIds = [];
    $scope.getDayIds($scope.booking.exclusionDays);
    $scope.datesBetween = $scope.getDates($scope.selectedDays[0], $scope.selectedDays[1]);

  });
    //Kijk of de datum niet al geboekt is.
   // if($scope.booking.roomReservations.length>0){
        API.get('api/v1/commune/'+ $cookieStore.get('TangoCommuneId') +'/room/4/booked/time/',{'comment':"comment"}).success(function (response){
            console.log(response);
        }).error(function (err){
            console.log(err);
        });

};

对于我的使用:

use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\Annotations\QueryParam;
use FOS\RestBundle\Request\ParamFetcher;
use FOS\RestBundle\View\View;
use JMS\Serializer\SerializationContext;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use FOS\RestBundle\Controller\Annotations\Post;
use FOS\RestBundle\Controller\Annotations\Get;
use FOS\RestBundle\Controller\Annotations\Delete;
use FOS\RestBundle\Controller\Annotations\Patch;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\Request;

刷新预订功能有效。但应该如此。当我使用{'评论':"评论"}进行API.get调用时。评论总是空的?我有完全相同的事情。工作所以我真的很困惑。我只想要请求接收此注释var。并且可以在服务器端获得它。一整天都在这。真的看不出什么是错的,为什么评论总是空的。我觉得很奇怪。所以我真的不明白为什么我的服务器没有这个评论。我试过了,{'评论' :"评论"}

  

的console.log(响应);给了我""

服务器响应成功。

1 个答案:

答案 0 :(得分:1)

显然,当我使用GET电话时。只有当我使用Patch或Post时,我才能为通话提供参数。