collection-crud/src/Controller/GpuCoreController.php

68 lines
1.9 KiB
PHP
Raw Permalink Normal View History

2022-09-30 10:49:02 -04:00
<?php declare(strict_types=1);
2022-09-29 20:09:31 -04:00
namespace App\Controller;
use App\Entity\GpuCore;
use App\Form\GPUCoreType;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
2022-09-30 10:49:02 -04:00
use Symfony\Component\HttpFoundation\{Request, Response};
2022-09-29 20:09:31 -04:00
use Symfony\Component\Routing\Annotation\Route;
#[Route('/gpu-core')]
2023-07-21 10:35:15 -04:00
class GpuCoreController extends AbstractController {
use FormControllerBase;
2022-09-30 10:48:14 -04:00
2023-07-21 10:35:15 -04:00
protected const ENTITY = GpuCore::class;
protected const TEMPLATE_PATH = 'gpu_core/';
protected const ROUTE_PREFIX = 'gpu-core_';
protected const FORM = GPUCoreType::class;
2022-09-30 10:48:14 -04:00
2023-07-21 10:35:15 -04:00
public function __construct(private readonly EntityManagerInterface $entityManager)
{
}
2022-09-30 10:48:14 -04:00
2023-07-21 10:35:15 -04:00
#[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',
]);
}
2022-09-29 20:09:31 -04:00
2023-07-21 10:35:15 -04:00
#[Route('/new', name: 'gpu-core_new', methods: ['GET', 'POST'])]
public function new(Request $request): Response
{
return $this->itemCreate($request, 'gpu_core');
}
2022-09-29 20:09:31 -04:00
2023-07-21 10:35:15 -04:00
#[Route('/{id}', name: 'gpu-core_show', methods: ['GET'])]
public function show(GpuCore $gPUCore): Response
{
return $this->itemView($gPUCore, 'gpu_core');
}
2022-09-29 20:09:31 -04:00
2023-07-21 10:35:15 -04:00
#[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');
}
2022-09-29 20:09:31 -04:00
2023-07-21 10:35:15 -04:00
#[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();
}
2022-09-29 20:09:31 -04:00
2023-07-21 10:35:15 -04:00
return $this->redirectToRoute('gpu-core_index', [], Response::HTTP_SEE_OTHER);
}
2022-09-29 20:09:31 -04:00
}