You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.2 KiB
39 lines
1.2 KiB
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
use App\Entity\Species;
|
|
use App\Form\SpeciesType;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
|
|
|
class SpeciesController extends AbstractController
|
|
{
|
|
#[Route('/species/add', name: 'app_add_species')]
|
|
#[IsGranted('ROLE_USER', message: 'You must be logged in to access this page.')]
|
|
public function new(Request $request, EntityManagerInterface $entityManager): Response
|
|
{
|
|
$species = new Species();
|
|
$form = $this->createForm(SpeciesType::class, $species);
|
|
|
|
$form->handleRequest($request);
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
|
|
|
$species = $form->getData();
|
|
|
|
$entityManager->persist($species);
|
|
$entityManager->flush();
|
|
|
|
return $this->redirectToRoute('app_add_species');
|
|
}
|
|
|
|
return $this->render('species/species.html.twig', [
|
|
'form' => $form->createView(),
|
|
]);
|
|
}
|
|
}
|