Bonjour,
J'ai plusieurs erreurs concernant la mise en ligne de mon application notamment celle-ci :
An exception occurred while executing 'SELECT t0.id AS id_1, t0.name AS name_2 FROM listing t0':
Notice: Undefined variable: argsCount
Malgré plusieurs forums et documentations je n'arrive toujours pas à afficher ma page.... :/
Si quelqu'un aurait une solution ça serait génial :)
Bonjour, d'accord bidule alors je met le code de mes fichiers,
Voici le fichier Listing.php
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
@ORM\Entity(repositoryClass="App\Repository\ListingRepository")
*/
class Listing
{
/**
/**
/**
public function getId()
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
Le fichier Task.php
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
@ORM\Entity(repositoryClass="App\Repository\TaskRepository")
*/
class Task
{
/**
/**
/**
/**
/**
/**
public function getId()
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
/**
/**
/**
/**
/**
/**
}
Fichier ListingRepository.php
<?php
namespace App\Repository;
use App\Entity\Listing;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
@method Listing[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class ListingRepository extends ServiceEntityRepository
{
public function construct(ManagerRegistry $registry)
{
parent::construct($registry, Listing::class);
}
// /*
// @return Listing[] Returns an array of Listing objects
// /
/
public function findByExampleField($value)
{
return $this->createQueryBuilder('l')
->andWhere('l.exampleField = :val')
->setParameter('val', $value)
->orderBy('l.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
/
public function findOneBySomeField($value): ?Listing
{
return $this->createQueryBuilder('l')
->andWhere('l.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
/
}
Fichier TaskRepository.php
<?php
namespace App\Repository;
use App\Entity\Task;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
@method Task[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class TaskRepository extends ServiceEntityRepository
{
public function construct(ManagerRegistry $registry)
{
parent::construct($registry, Task::class);
}
// /*
// @return Task[] Returns an array of Task objects
// /
/
public function findByExampleField($value)
{
return $this->createQueryBuilder('t')
->andWhere('t.exampleField = :val')
->setParameter('val', $value)
->orderBy('t.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
/
public function findOneBySomeField($value): ?Task
{
return $this->createQueryBuilder('t')
->andWhere('t.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
/
}
ListingController.php :
<?php
namespace App\Controller;
use App\Entity\Listing;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
class ListingController extends AbstractController
{
/**
@Route("/{listingId}", name="show", requirements={"listingId"="\d+"})
*/
public function show(EntityManagerInterface $entityManager, $listingId = null)
{
$listings = $entityManager->getRepository(Listing::class)->findAll();
if (!empty($listingId)){
$currentListing = $entityManager->getRepository(Listing::class)->find($listingId);
}
if (empty($currentListing)){
$currentListing = current($listings);
}
return $this->render("listing.html.twig", ['listings' => $listings, 'currentListing' => $currentListing]);
}
/**
@Route("/new", methods="POST", name="create")
*/
public function create(EntityManagerInterface $entityManager, Request $request)
{
$name = $request->get('name');
if(empty($name)) {
$this->addFlash(
"warning",
"Un nom de liste est obligatoire !"
);
return $this->redirectToRoute('listing_show');
}
$listing = new Listing();
$listing->setName($name);
try {
$entityManager->persist($listing);
$entityManager->flush();
$this->addFlash(
"success",
"La liste « $name » a été crée avec succès"
);
} catch (UniqueConstraintViolationException $e) {
$this->addFlash(
"warning",
"La liste $name existe déjà."
);
}
return $this->redirectToRoute('listing_show');
}
/**
@Route("/{listingId}/delete", name="delete", requirements={"listingId"="\d+"})
*/
public function delete(EntityManagerInterface $entityManager, $listingId)
{
$listing = $entityManager->getRepository(Listing::class)->find($listingId);
if (empty($listing)) {
$this->addFlash(
"warning",
"Impossible de supprimer de la liste"
);
} else {
$entityManager->remove($listing);
$entityManager->flush();
$name = $listing->getName();
$this->addFlash(
"success",
"La liste $name à été supprimé avec succès"
);
}
return $this->redirectToRoute('listing_show');
}
}
TaskController.php :
<?php
namespace App\Controller;
use App\Entity\Task;
use App\Entity\Listing;
use App\Form\TaskType;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
/**
@Route("{listingId}/task", name="task_", requirements={"listingId"="\d+"})
*/
class TaskController extends AbstractController
{
/**
@Route("/new", name="create")
*/
public function create(EntityManagerInterface $entityManager, Request $request, $listingId)
{
$listing = $entityManager->getRepository(Listing::class)->find($listingId);
$task = new Task();
$task->setListing($listing);
$form = $this->createForm(TaskType::class, $task);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($task);
$entityManager->flush();
return $this->redirectToRoute('listing_show', ['listingId' => $listingId]);
}
return $this->render('task.html.twig', ['form' => $form->createView()]);
}
/**
@Route("/{taskId}/edit", name="edit", requirements={"taskId"="\d+"})
*/
public function edit(EntityManagerInterface $entityManager, Request $request, $listingId, $taskId)
{
$task = $entityManager->getRepository(Task::class)->find($taskId);
if (empty($task)) {
$this->addFlash(
'warning',
'Impossible de modifier la tâche'
);
return $this->redirectToRoute('listing_show', ['listingId' => $listingId]);
}
$name = $task->getName();
$form = $this->createForm(TaskType::class, $task);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->flush();
$this->addFlash(
'success',
"La tâche $name a été modifiée avec succès"
);
return $this->redirectToRoute('listing_show', ['listingId' => $listingId]);
}
return $this->render('task.html.twig', ['form' => $form->createView()]);
}
/**
@Route("/{taskId}/delete", name="delete", requirements={"taskId"="\d+"})
*/
public function delete(EntityManagerInterface $entityManager, Request $request, $listingId, $taskId)
{
$task = $entityManager->getRepository(Task::class)->find($taskId);
if (empty($task)) {
$this->addFlash(
'warning',
'Impossible de supprimer la tâche'
);
return $this->redirectToRoute('listing_show', ['listingId' => $listingId]);
} else {
$name = $task->getName();
$entityManager->remove($task);
$entityManager->flush();
$this->addFlash(
'success',
"La tâche $name a été supprimer"
);
}
return $this->redirectToRoute('listing_show', ['listingId' => $listingId]);
}
}
J'ai réussi à faire marcher mon application !!
En gros j'ai tout supprimé mes fichiers symfony de Filezilla.
1 - Dans mon dossier application_web j'ai crée en ligne de commande CMD un fichier .htaccess en faisant : composer require symfony/apache-pack
Celui-ci c'est crée dans le dossier public/
2 - Vider le cache en faisant :
php bin/console cache:clear
3 - Vider le cache de production :
php bin/console cache:clear --env=prod
4 - Remettre tous les fichiers dans le serveur filleZilla avec les infos de la base de donnée de l'hébergeur et ça marche !