[ERROR] Symfony 4. Je ne comprends pas cette erreur.
Bonjour à tous!
Je travaille sur un projet symfony 4.3. Je crée un CRUD manuellement (sans la commande make:crud) pour une entité Appointment, pour gérer l'ajout, la modification et la suppression de rdv. J'ai eu cette erreur que je ne comprends pas :
Citation:
Catchable Fatal Error: Object of class App\Entity\Customer could not be converted to string
Je vous mets rapidement les étapes que j'ai effectué:
_ création de l'entité Appointment (id, idUser, idCustomer, idPlace, date) avec relation (entités User, Customer, Place).
_ création d'un AppointmentController, avec les méthodes index et new, ainsi que les templates correspondants.
Quand je vais sur la route /appointment qui fait appel à la méthode index, j'ai bien mon tableau qui s'affiche même si je n'ai pas encore de données dans ma liste.
Mais quand je vais sur la route /appointment/new pour créer un rdv, c'est là que cette erreur apparaît. Je ne comprends pas ce que j'ai loupé ou alors où est mon erreur dans mon code.
Pourriez-vous m'éclairer svp ?
Voici le code du Controller:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
<?php
namespace App\Controller;
use App\Entity\Appointment;
use App\Form\AppointmentType;
use App\Repository\AppointmentRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class AppointmentController extends AbstractController
{
/**
* @Route("/appointment", name="appointment")
*/
public function index(AppointmentRepository $appointmentRepository)
{
return $this->render('appointment/index.html.twig', [
'appointments' => $appointmentRepository->findAll(),
]);
}
/**
* @Route("/appointment/new", name = "appointment_new", methods = {"GET", "POST"})
*/
public function new(Request $request) : Response {
$appointments = new Appointment();
$form = $this->createForm(AppointmentType::class, $appointments);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($appointments);
$em->flush();
return $this->redirectToRoute('appointment');
}
return $this->render('appointment/new.html.twig', [
'appointments' => $appointments,
'form' => $form->createView(),
]);
}
} |
Le code de l'entité Appointment) :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
<?php
namespace App\Entity;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\AppointmentRepository")
*/
class Appointment
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\OneToOne(targetEntity="App\Entity\User", inversedBy="appointment", cascade={"persist", "remove"})
*/
private $idUser;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Customer", inversedBy="appointment", cascade={"persist", "remove"})
*/
private $idCustomer;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Place", inversedBy="appointment", cascade={"persist", "remove"})
*/
private $idPlace;
/**
* @ORM\Column(type="datetime")
*/
private $date;
public function getId(): ?int
{
return $this->id;
}
public function getIdUser(): ?User
{
return $this->idUser;
}
public function setIdUser(?User $idUser): self
{
$this->idUser = $idUser;
return $this;
}
public function getIdCustomer(): ?Customer
{
return $this->idCustomer;
}
public function setIdCustomer(?Customer $idCustomer): self
{
$this->idCustomer = $idCustomer;
return $this;
}
public function getIdPlace(): ?Place
{
return $this->idPlace;
}
public function setIdPlace(?Place $idPlace): self
{
$this->idPlace = $idPlace;
return $this;
}
public function getDate(): ?DateTimeInterface // il y avait un \ avant chaque DateTimeInterface
{
return $this->date;
}
public function setDate(DateTimeInterface $date): self
{
$this->date = $date;
return $this;
}
} |
Merci!