collection-crud/src/Controller/GpuCoreController.php

67 lines
2.1 KiB
PHP
Raw 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;
2022-09-30 10:48:14 -04:00
use App\Traits\FormControllerTrait;
2022-09-29 20:09:31 -04:00
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')]
class GpuCoreController extends AbstractController
{
2022-09-30 10:49:02 -04:00
use FormControllerTrait;
2022-09-30 10:48:14 -04:00
2022-09-30 10:49:02 -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
2022-09-30 10:49:02 -04:00
public function __construct(private readonly EntityManagerInterface $entityManager)
{
}
2022-09-30 10:48:14 -04:00
2022-09-29 20:09:31 -04:00
#[Route('/', name: 'gpu-core_index', methods: ['GET'])]
2022-09-30 10:48:14 -04:00
public function index(): Response
2022-09-29 20:09:31 -04:00
{
2022-09-30 10:49:02 -04:00
return $this->indexView('gpu_cores', [
'brand' => 'asc',
'architecture' => 'asc',
'name' => 'asc',
'variant' => 'asc',
]);
2022-09-29 20:09:31 -04:00
}
#[Route('/new', name: 'gpu-core_new', methods: ['GET', 'POST'])]
2022-09-30 10:48:14 -04:00
public function new(Request $request): Response
2022-09-29 20:09:31 -04:00
{
2022-09-30 10:49:02 -04:00
return $this->itemCreate($request, 'gpu_core');
2022-09-29 20:09:31 -04:00
}
#[Route('/{id}', name: 'gpu-core_show', methods: ['GET'])]
public function show(GpuCore $gPUCore): Response
{
2022-09-30 10:49:02 -04:00
return $this->itemView($gPUCore, 'gpu_core');
2022-09-29 20:09:31 -04:00
}
#[Route('/{id}/edit', name: 'gpu-core_edit', methods: ['GET', 'POST'])]
2022-09-30 10:48:14 -04:00
public function edit(Request $request, GpuCore $gPUCore): Response
2022-09-29 20:09:31 -04:00
{
2022-09-30 10:49:02 -04:00
return $this->itemUpdate($request, $gPUCore, 'gpu_core');
2022-09-29 20:09:31 -04:00
}
#[Route('/{id}', name: 'gpu-core_delete', methods: ['POST'])]
public function delete(Request $request, GpuCore $gPUCore, EntityManagerInterface $entityManager): Response
{
2022-09-30 10:49:02 -04:00
if ($this->isCsrfTokenValid('delete' . $gPUCore->getId(), $request->request->get('_token'))) {
2022-09-29 20:09:31 -04:00
$entityManager->remove($gPUCore);
$entityManager->flush();
}
return $this->redirectToRoute('gpu-core_index', [], Response::HTTP_SEE_OTHER);
}
}