在字符串 symfony 3.4 上调用成员函数 format()

穆罕默德·萨科

发送电子邮件后,我试图在我的数据库中注册一个新约会,但它显示了一个错误:Call to a member function format() on string, in vendor\doctrine\dbal\lib\Doctrine\DBAL\Types \DateTimeType.php

因为在预订实体中,我需要注册日期时间类型的日期和时间。这是预订实体:

 <?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;
}
 }

这是控制器:

   public function patientHandleBookingAction(Request $request){

      $id = $request->query->get('id');
     $date = $request->query->get('date');
     $time = $request->query->get('time');
    // $user = $this->getUser();

    $em = $this->getDoctrine()->getManager();
    $repoPatient = $em->getRepository('DoctixPatientBundle:Patient');
    $patient = $repoPatient->findOneBy(array(
        'user' => $this->getUser()
    ));

    $repoMedecin = $em->getRepository('DoctixMedecinBundle:Medecin');
    $medecin = $repoMedecin->findOneBy(array(
        'id' => $request->query->get("idMedecin")));


    $mailer = $this->get('mailer');
    $message = (new \Swift_Message('Email de Confirmaton'))
        ->setFrom("[email protected]")
        ->setTo($patient->getUser()->getUsername())
        ->setBody(
            $this->renderView(
                // app/Resources/views/Emails/registration.html.twig
                'Emails/registration.html.twig',
                array('name' => 'mam')
            ),
            'text/html'
        );

    $mailer->send($message);
    if($mailer){

      $booking = new Booking();
      $booking->setMedecin($medecin);
      $booking->setPatient($patient);
      $booking->setDateRdv('date');
      $booking->setHeureRdv('time');
      $booking->setValiderRdv(0);


    }

    $em->persist($booking);
    $em->flush();

    // A remplacer par un contenu plus approprié
    return $this->render('DoctixPatientBundle:Patient:confirm.html.twig',array(
            'time' => $request->query->get("time"),
            'date' => $request->query->get("date"),
            'medecin' => $medecin,
            'patient' => $patient,
           // 'date' => $date,
           // 'time' => $time
));

}

谢谢

贾米森·利马

发生此错误是因为您尝试将日期和时间设置为预订实体上的字符串。

  $booking->setDateRdv('date');
  $booking->setHeureRdv('time');

尝试将其更改为:

  $booking->setDateRdv(new \DateTime($date));
  $booking->setHeureRdv(new \DateTime($time));

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在laravel中的字符串上调用成员函数format()

Laravel错误:在字符串上调用成员函数format()

Laravel 错误:在字符串上调用成员函数 format()

在null,Symfony 4上调用成员函数encodePassword()

在symfony4中的null上调用成员函数setDp()

错误:在数组 Symfony 3 上调用成员函数 contains()

在laravel 5.5中的字符串上调用成员函数format()

PHP 致命错误:在字符串上调用成员函数 format()

在字符串 laravel 5.8 上调用成员函数 all()

在字符串OOP PHP上调用成员函数query()

返回日期格式返回对字符串的成员函数format()的调用

在非对象上调用成员函数get()-Symfony和Silex

在空“ Symfony Php”上调用成员函数get()

Symfony 2错误:在非对象上调用成员函数get()

symfony 和棘轮在 null 上调用成员函数 get()

Symfony:错误:在非对象上调用成员函数get()

错误:在字符串上调用成员函数setPayrollperiodid()

在字符串上调用成员函数all()(查看:

PHP:在字符串上调用成员函数contains()

致命错误:在字符串上调用成员函数prepare()

Yii 2 在字符串上调用成员函数 saveAs()

错误:在字符串上调用成员函数 addDays()

致命错误:在字符串上调用成员函数

在字符串上调用成员函数addEagerConstraints()

在字符串上调用成员函数fill()

在字符串上调用成员函数 setDate()

在 Yii 的字符串上调用成员函数 saveAs()

在laravel中的字符串上调用成员函数latest()

在字符串上调用成员函数guessExtension()