|
|
@ -5,6 +5,7 @@ namespace App\Controller; |
|
|
|
use App\Entity\Pokemon; |
|
|
|
use App\Form\PokemonType; |
|
|
|
use App\Repository\PokemonRepository; |
|
|
|
use phpDocumentor\Reflection\Types\Array_; |
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
|
@ -18,8 +19,16 @@ class PokemonController extends AbstractController |
|
|
|
/** |
|
|
|
* @Route("/", name="pokemon_index", methods={"GET"}) |
|
|
|
*/ |
|
|
|
public function index(PokemonRepository $pokemonRepository): Response |
|
|
|
public function index(PokemonRepository $pokemonRepository, Request $request): Response |
|
|
|
{ |
|
|
|
// Si l'utilisateur saisit un mot clé |
|
|
|
if ($pokemonSearchTerm = $request->query->get('keyword')) { |
|
|
|
return $this->render('pokemon/index.html.twig', [ |
|
|
|
'pokemon' => $pokemonRepository->findPokemonsWithSearchTerm($pokemonSearchTerm), |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
// Sinon on affiche tout les pokemons |
|
|
|
return $this->render('pokemon/index.html.twig', [ |
|
|
|
'pokemon' => $pokemonRepository->findAll(), |
|
|
|
]); |
|
|
@ -83,7 +92,7 @@ class PokemonController extends AbstractController |
|
|
|
*/ |
|
|
|
public function delete(Request $request, Pokemon $pokemon): Response |
|
|
|
{ |
|
|
|
if ($this->isCsrfTokenValid('delete'.$pokemon->getId(), $request->request->get('_token'))) { |
|
|
|
if ($this->isCsrfTokenValid('delete' . $pokemon->getId(), $request->request->get('_token'))) { |
|
|
|
$entityManager = $this->getDoctrine()->getManager(); |
|
|
|
$entityManager->remove($pokemon); |
|
|
|
$entityManager->flush(); |
|
|
|