2026-06-02 01:04:08 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
|
2026-06-02 22:01:42 +02:00
|
|
|
use App\Entity\Restaurant;
|
|
|
|
|
use App\Repository\SubjectRepository;
|
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
2026-06-02 18:46:00 +02:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
2026-06-02 22:01:42 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
|
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
|
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
2026-06-02 01:04:08 +02:00
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
|
|
|
|
2026-06-02 20:30:18 +02:00
|
|
|
class SubjectController extends AbstractController
|
2026-06-02 01:04:08 +02:00
|
|
|
{
|
|
|
|
|
#[Route('/')]
|
2026-06-02 22:01:42 +02:00
|
|
|
public function index(
|
|
|
|
|
Request $request,
|
|
|
|
|
EntityManagerInterface $em,
|
|
|
|
|
SubjectRepository $repo,
|
|
|
|
|
): Response {
|
|
|
|
|
$subject = new Restaurant();
|
|
|
|
|
$subject->setName("MyRestaurant");
|
|
|
|
|
|
|
|
|
|
$form = $this->createFormBuilder($subject)
|
|
|
|
|
->add('name', TextType::class)
|
|
|
|
|
->add('save', SubmitType::class)
|
|
|
|
|
->getForm();
|
|
|
|
|
|
|
|
|
|
$form->handleRequest($request);
|
|
|
|
|
|
|
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
2026-06-03 00:42:51 +02:00
|
|
|
$subject->setCreatedBy($this->getUser());
|
2026-06-02 22:01:42 +02:00
|
|
|
$em->persist($subject);
|
|
|
|
|
$em->flush();
|
|
|
|
|
|
|
|
|
|
return $this->redirectToRoute('app_subject_index');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$subjects = $repo->findAll();
|
|
|
|
|
|
|
|
|
|
return $this->render('index/page.html.twig', [
|
|
|
|
|
'form' => $form,
|
|
|
|
|
'subjects' => $subjects,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[Route('/', 'subject_new', methods: ["POST"])]
|
|
|
|
|
public function save(): RedirectResponse
|
2026-06-02 01:04:08 +02:00
|
|
|
{
|
2026-06-02 22:01:42 +02:00
|
|
|
return $this->redirect('/');
|
2026-06-02 01:04:08 +02:00
|
|
|
}
|
|
|
|
|
}
|