POSTMANからREST APIを介してDBにエントリをPOSTしようとしています。私はsymfonyフレームワークを使用しています。integer datetimeのメンバー関数format()を呼び出す
{
"error": {
"code": 500,
"message": "Internal Server Error",
"exception": [
{
"message": "Error: Call to a member function format() on integer",
"class": "Symfony\\Component\\Debug\\Exception\\FatalErrorException",
"trace": [
{
"namespace": "",
"short_class": "",
"class": "",
"type": "",
"function": "",
"file": "C:\\xampp\\htdocs\\joel\\proj3\\vendor\\doctrine\\dbal\\lib\\Doctrine\\DBAL\\Types\\DateTimeType.php",
"line": 53,
"args": []
}
]
}
]
}
}
これはコードです:私はDateTimeオブジェクトを待っているあなたのsetCreatedate
セッターを推測
<?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);
}
}
男.....あなたは人生の節約者です... DBが更新されています。 Thanxx so much bruh .....:D – jcoder