создал crud под названием admin , конечно туда может зайти любой sitename.com/admin и использовать методы REST new show edit delete
src/Controller/AdminController.php
<?php
namespace App\Controller;
use App\Entity\Admin;
use App\Form\AdminType;
use App\Repository\AdminRepository;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/admin")
*/
class AdminController extends Controller
{
/**
* @Route("/", name="admin_index", methods="GET")
*/
public function index(AdminRepository $adminRepository): Response
{
return $this->render('admin/index.html.twig', ['admins' => $adminRepository->findAll()]);
}
/**
* @Route("/new", name="admin_new", methods="GET|POST")
*/
public function new(Request $request): Response
{
$admin = new Admin();
$form = $this->createForm(AdminType::class, $admin);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($admin);
$em->flush();
return $this->redirectToRoute('admin_index');
}
return $this->render('admin/new.html.twig', [
'admin' => $admin,
'form' => $form->createView(),
]);
}
/**
* @Route("/{id}", name="admin_show", methods="GET")
*/
public function show(Admin $admin): Response
{
return $this->render('admin/show.html.twig', ['admin' => $admin]);
}
/**
* @Route("/{id}/edit", name="admin_edit", methods="GET|POST")
*/
public function edit(Request $request, Admin $admin): Response
{
$form = $this->createForm(AdminType::class, $admin);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('admin_edit', ['id' => $admin->getId()]);
}
return $this->render('admin/edit.html.twig', [
'admin' => $admin,
'form' => $form->createView(),
]);
}
/**
* @Route("/{id}", name="admin_delete", methods="DELETE")
*/
public function delete(Request $request, Admin $admin): Response
{
if ($this->isCsrfTokenValid('delete'.$admin->getId(), $request->request->get('_token'))) {
$em = $this->getDoctrine()->getManager();
$em->remove($admin);
$em->flush();
}
return $this->redirectToRoute('admin_index');
}
}
и вопрос в том как установить пароль на этот контролер ? но при этом метод show был бы доступен всем без пароля ?
Апостиль в Лос-Анджелесе без лишних нервов и бумажной волокиты
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости