collection-crud/src/Controller/GpuCoreController.php

69 lines
2.2 KiB
PHP

<?php declare(strict_types=1);
namespace App\Controller;
use App\Entity\GpuCore;
use App\Form\GPUCoreType;
use App\Traits\FormControllerTrait;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\{Request, Response};
use Symfony\Component\Routing\Annotation\Route;
#[Route('/gpu-core')]
class GpuCoreController extends AbstractController
{
use FormControllerTrait;
protected const ENTITY = GpuCore::class;
protected const TEMPLATE_PATH = 'gpu_core/';
protected const ROUTE_PREFIX = 'gpu-core_';
protected const FORM = GPUCoreType::class;
public function __construct(private readonly EntityManagerInterface $entityManager)
{
}
#[Route('/', name: 'gpu-core_index', methods: ['GET'])]
public function index(): Response
{
return $this->indexView('gpu_cores', [
'brand' => 'asc',
'processNode' => 'desc',
'generationName' => 'asc',
'architecture' => 'asc',
'name' => 'asc',
'variant' => 'asc',
]);
}
#[Route('/new', name: 'gpu-core_new', methods: ['GET', 'POST'])]
public function new(Request $request): Response
{
return $this->itemCreate($request, 'gpu_core');
}
#[Route('/{id}', name: 'gpu-core_show', methods: ['GET'])]
public function show(GpuCore $gPUCore): Response
{
return $this->itemView($gPUCore, 'gpu_core');
}
#[Route('/{id}/edit', name: 'gpu-core_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, GpuCore $gPUCore): Response
{
return $this->itemUpdate($request, $gPUCore, 'gpu_core');
}
#[Route('/{id}', name: 'gpu-core_delete', methods: ['POST'])]
public function delete(Request $request, GpuCore $gPUCore, EntityManagerInterface $entityManager): Response
{
if ($this->isCsrfTokenValid('delete' . $gPUCore->getId(), $request->request->get('_token'))) {
$entityManager->remove($gPUCore);
$entityManager->flush();
}
return $this->redirectToRoute('gpu-core_index', [], Response::HTTP_SEE_OTHER);
}
}