Postman Symfony日期错误

时间:2017-08-03 06:13:20

标签: sql rest symfony postman

我试图通过POSTMAN通过REST API将条目发布到数据库。我正在使用Symfony框架。我是这个领域的新手,不能轻易理解和纠正错误。

这是控制器的代码:

<?php

namespace AcsUserBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\FOSRestController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use FOS\RestBundle\View\View;
use AcsUserBundle\Entity\User;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;

class UserController extends FOSRestController
{


   /**
 * @Rest\Post("/user/")
 */
 public function postAction(Request $request)
 {
   $data = new User;
   $personid = $request->get('personid');
   $privilagevalueid = $request->get('privilagevalueid');
   $username = $request->get('username');
   $password = $request->get('password');


   $createdate =strtotime($request->get('createdate'));



 if(empty($personid) || empty($privilagevalueid) || empty($username)|| empty($password)|| empty($createdate))
 {
   return new View("NULL VALUES ARE NOT ALLOWED", Response::HTTP_NOT_ACCEPTABLE); 
 } 



  $data->setPersonid($personid);
  $data->setPrivilagevalueid($privilagevalueid);
  $data->setUsername($username);
  $data->setPassword($password);
  $data->setCreatedate($createdate);



  $em = $this->getDoctrine()->getManager();
  $em->persist($data);
  $em->flush();
  return new View("User Added Successfully", Response::HTTP_OK);
 }


}

这是错误:

{
    "error": {
        "code": 500,
        "message": "Internal Server Error",
        "exception": [
            {
                "message": "Parse Error: syntax error, unexpected '='",
                "class": "Symfony\\Component\\Debug\\Exception\\FatalErrorException",
                "trace": [
                    {
                        "namespace": "",
                        "short_class": "",
                        "class": "",
                        "type": "",
                        "function": "",
                        "file": "C:\\xampp\\htdocs\\joel\\proj3\\src\\AcsUserBundle\\Controller\\UserController.php",
                        "line": 30,
                        "args": []
                    }
                ]
            }
        ]
    }
}

1 个答案:

答案 0 :(得分:2)

= $createdate =strtotime($request->get('createdate'));

之后再添加一个空格