String 对字符串symfony 3.4调用成员函数format()
发送电子邮件后,我试图在数据库中注册一个新约会,但它显示了一个错误:调用字符串上的成员函数format(), 在vendor\doctor\dbal\lib\doctor\dbal\Types\DateTimeType.php中 , 因为在预订实体中,有我需要注册的日期和时间,它们是日期时间类型。 以下是预订实体:String 对字符串symfony 3.4调用成员函数format(),string,symfony,datetime,format,String,Symfony,Datetime,Format,发送电子邮件后,我试图在数据库中注册一个新约会,但它显示了一个错误:调用字符串上的成员函数format(), 在vendor\doctor\dbal\lib\doctor\dbal\Types\DateTimeType.php中 , 因为在预订实体中,有我需要注册的日期和时间,它们是日期时间类型。 以下是预订实体: <?php namespace Doctix\FrontBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** *
<?php
namespace Doctix\FrontBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Booking
*
* @ORM\Table(name="booking")
*
class Booking
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var \DateTime
*
*@ORM\Column(name="date_rdv", type="datetime", nullable=true)
*/
private $dateRdv;
/**
* @var \DateTime
*
*@ORM\Column(name="heure_rdv", type="datetime", nullable=true)
*/
private $heureRdv;
/**
* @var bool
*
*@ORM\Column(name="valider_rdv", type="boolean", nullable=true)
*/
private $validerRdv;
/**
* @ORM\ManyToOne(targetEntity="Doctix\MedecinBundle\Entity\Medecin")
* @ORM\JoinColumn(nullable=true)
*/
private $medecin;
/**
* @ORM\ManyToOne(targetEntity="Doctix\PatientBundle\Entity\Patient")
* @ORM\JoinColumn(nullable=true)
*/
private $patient;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set dateRdv
*
* @param \DateTime $dateRdv
*
* @return Booking
*/
public function setDateRdv($dateRdv)
{
$this->dateRdv = $dateRdv;
return $this;
}
/**
* Get dateRdv
*
* @return \DateTime
*/
public function getDateRdv()
{
return $this->dateRdv;
}
/**
* Set heureRdv
*
* @param \DateTime $heureRdv
*
* @return Booking
*/
public function setHeureRdv($heureRdv)
{
$this->heureRdv = $heureRdv;
return $this;
}
/**
* Get heureRdv
*
* @return \DateTime
*/
public function getHeureRdv()
{
return $this->heureRdv;
}
/**
* Set validerRdv
*
* @param boolean $validerRdv
*
* @return Booking
*/
public function setValiderRdv($validerRdv)
{
$this->validerRdv = $validerRdv;
return $this;
}
/**
* Get validerRdv
*
* @return bool
*/
public function getValiderRdv()
{
return $this->validerRdv;
}
/**
* Set medecin
*
* @param \Doctix\MedecinBundle\Entity\Medecin $medecin
* @return Booking
*/
public function setMedecin(\Doctix\MedecinBundle\Entity\Medecin $medecin)
{
$this->medecin = $medecin;
return $this;
}
/**
* Get medecin
*
* @return \Doctix\MedecinBundle\Entity\Medecin
*/
public function getMedecin()
{
return $this->medecin;
}
/**
* Set patient
*
* @param \Doctix\PatientBundle\Entity\Patient $patient
* @return Booking
*/
public function setPatient(\Doctix\PatientBundle\Entity\Patient $patient)
{
$this->patient = $patient;
return $this;
}
/**
* Get patient
*
* @return \Doctix\PatientBundle\Entity\Patient
*/
public function getPatient()
{
return $this->patient;
}
}
谢谢发生此错误是因为您试图在预订实体上将日期和时间设置为字符串
$booking->setDateRdv('date');
$booking->setHeureRdv('time');
尝试将其更改为:
$booking->setDateRdv(new \DateTime($date));
$booking->setHeureRdv(new \DateTime($time));
$booking->setDateRdv(new \DateTime($date));
$booking->setHeureRdv(new \DateTime($time));