collection-crud/src/Controller/BrandController.php

57 lines
1.5 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\Brand;
use App\Form\BrandType;
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('/brand')]
2023-07-21 10:35:15 -04:00
class BrandController extends AbstractController {
use FormControllerBase;
protected const ENTITY = Brand::class;
protected const TEMPLATE_PATH = 'brand/';
protected const ROUTE_PREFIX = 'brand_';
protected const FORM = BrandType::class;
public function __construct(private readonly EntityManagerInterface $entityManager)
{
}
#[Route('/', name: 'brand_index', methods: ['GET'])]
public function index(): Response
{
return $this->itemListView('brands', [
'name' => 'asc',
]);
}
#[Route('/new', name: 'brand_new', methods: ['GET', 'POST'])]
public function new(Request $request): Response
{
return $this->itemCreate($request, 'brand');
}
#[Route('/{id}', name: 'brand_show', methods: ['GET'])]
public function show(Brand $brand): Response
{
return $this->itemView($brand, 'brand');
}
#[Route('/{id}/edit', name: 'brand_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, Brand $brand): Response
{
return $this->itemUpdate($request, $brand, 'brand');
}
#[Route('/{id}', name: 'brand_delete', methods: ['POST'])]
public function delete(Request $request, Brand $brand): Response
{
return $this->deleteCSRF($request, $brand);
}
2022-09-29 20:09:31 -04:00
}