我的日期有问题。也许我在序列化过程中不了解某些内容,但是,例如,我何时将日期时间发送到 Api-Platform (Symfony)
dateEvaluation: "2017-12-05T11:52:00.000Z"
我收到此错误消息
Cannot create an instance of DateTime from serialized data because its constructor requires parameter "time" to be present.
这是我的实体
<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass="App\Repository\EvaluationRepository")
* @ORM\HasLifecycleCallbacks()
* @ApiResource(attributes={
* "normalization_context"={
* "groups"={"Evaluation"}
* }
* })
*/
class Evaluation
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"NotesEvaluations", "Evaluation"})
*/
private $id;
/**
* @var \DateTime
* @ORM\Column(type="datetime")
* @Groups({"Evaluation"})
*/
private $created;
/**
* @var \DateTime
* @ORM\Column(type="datetime")
* @Groups({"Evaluation"})
*/
private $updated;
/**
* @var \DateTime
* @ORM\Column(type="datetime")
* @Groups({"Evaluation"})
*/
private $dateEvaluation;
/**
* @var string
*
* @ORM\Column(type="text")
* @Groups({"Evaluation"})
*/
private $commentaire;
/**
* @var
*
* @ORM\ManyToOne(targetEntity="App\Entity\Personnel")
* @Groups({"NotesEvaluations", "Evaluation"})
*/
private $auteur;
/**
* @var
*
* @ORM\ManyToMany(targetEntity="App\Entity\Personnel")
*/
private $autorises;
/**
* @var integer
*
* @ORM\Column(type="integer")
*/
private $annee;
/**
* @var
*
* @ORM\ManyToOne(targetEntity="App\Entity\Module", inversedBy="evaluations")
* @Groups({"Evaluation"})
*/
private $module;
/**
* @var Boolean
*
* @ORM\Column(type="boolean")
* @Groups({"NotesEvaluations"})
*/
private $visible;
/**
* @var Boolean
*
* @ORM\Column(type="boolean")
* @Groups({"NotesEvaluations"})
*/
private $modifiable;
/**
* @var
*
* @ORM\ManyToOne(targetEntity="App\Entity\TypeGroupe")
* @Groups({"Evaluation"})
*/
private $typegroupe;
/**
* @var float
*
* @ORM\Column(type="decimal")
* @Groups({"Evaluation"})
*/
private $coefficient;
/**
* @return float
*/
public function getCoefficient(): float
{
return $this->coefficient;
}
/**
* @return mixed
*/
public function getTypegroupe()
{
return $this->typegroupe;
}
/**
* @param mixed $typegroupe
*/
public function setTypegroupe($typegroupe): void
{
$this->typegroupe = $typegroupe;
}
/**
* @return \DateTime
*/
public function getDateEvaluation(): \DateTime
{
return $this->dateEvaluation;
}
/**
* @param \DateTime $dateEvaluation
*/
public function setDateEvaluation(\DateTime $dateEvaluation): void
{
$this->dateEvaluation = $dateEvaluation;
}
/**
* @return string
*/
public function getCommentaire(): string
{
return $this->commentaire;
}
/**
* @param string $commentaire
*/
public function setCommentaire(string $commentaire): void
{
$this->commentaire = $commentaire;
}
/**
* @param float $coefficient
*/
public function setCoefficient(float $coefficient): void
{
$this->coefficient = $coefficient;
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @return \DateTime
*/
public function getCreated(): \DateTime
{
return $this->created;
}
/**
* @param \DateTime $created
*/
public function setCreated(\DateTime $created): void
{
$this->created = $created;
}
/**
* @return \DateTime
*/
public function getUpdated(): \DateTime
{
return $this->updated;
}
/**
* @param \DateTime $updated
*/
public function setUpdated(\DateTime $updated): void
{
$this->updated = $updated;
}
/**
* @return mixed
*/
public function getAuteur()
{
return $this->auteur;
}
/**
* @param mixed $auteur
*/
public function setAuteur($auteur): void
{
$this->auteur = $auteur;
}
/**
* @return mixed
*/
public function getAutorises()
{
return $this->autorises;
}
/**
* @param mixed $autorises
*/
public function setAutorises($autorises): void
{
$this->autorises = $autorises;
}
/**
* @return int
*/
public function getAnnee(): int
{
return $this->annee;
}
/**
* @param int $annee
*/
public function setAnnee(int $annee): void
{
$this->annee = $annee;
}
/**
* @return mixed
*/
public function getModule()
{
return $this->module;
}
/**
* @param mixed $module
*/
public function setModule($module): void
{
$this->module = $module;
}
/**
* @return bool
*/
public function isVisible(): bool
{
return $this->visible;
}
/**
* @param bool $visible
*/
public function setVisible(bool $visible): void
{
$this->visible = $visible;
}
/**
* @return bool
*/
public function isModifiable(): bool
{
return $this->modifiable;
}
/**
* @param bool $modifiable
*/
public function setModifiable(bool $modifiable): void
{
$this->modifiable = $modifiable;
}
/**
* @ORM\PreUpdate
*/
public function updateDate(): void
{
$this->setUpdated(new \Datetime());
}
public function __construct()
{
$this->setCreated(new \Datetime());
$this->setUpdated(new \Datetime());
}
}
我不明白为什么缺少“时间”。也许它是用于创建或更新的字段?无论如何,创建和更新的字段使用 ApiPlatform 返回一个带有时区的对象......
created:
{timezone: {name: "Europe/Paris",…}, offset: 561, timestamp: -62169984561}
offset:561
timestamp:-62169984561
timezone:{name: "Europe/Paris",…}
谢谢你的帮助。大卫