first commit symfony 6
This commit is contained in:
85
src/Controller/ConfigController.php
Normal file
85
src/Controller/ConfigController.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
use App\Entity\Config as Entity;
|
||||
use App\Form\ConfigType as Form;
|
||||
|
||||
class ConfigController extends AbstractController
|
||||
{
|
||||
private $data="config";
|
||||
private $entity="App\Entity\Config";
|
||||
private $twig="Config/";
|
||||
private $route="app_admin_config";
|
||||
|
||||
public function list($access): Response
|
||||
{
|
||||
return $this->render($this->twig.'list.html.twig',[
|
||||
"useheader"=>true,
|
||||
"usemenu"=>false,
|
||||
"usesidebar"=>true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function listrender($access,$category,ManagerRegistry $em): Response
|
||||
{
|
||||
$datas = $em->getRepository($this->entity)->findBy(["visible"=>true,"category"=>$category]);
|
||||
|
||||
return $this->render($this->twig.'render.html.twig',[
|
||||
$this->data."s" => $datas,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update($access,$id,Request $request,ManagerRegistry $em): Response
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
if(!$data->getValue())
|
||||
$data->setValue($request->getSession()->get($data->getId()));
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"update","id"=>$data->getId(),"type"=>$data->getType(),"required"=>$data->isRequired()));
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$em->getManager()->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->twig.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete($access,$id,Request $request,ManagerRegistry $em): Response
|
||||
{
|
||||
// Récupération de l'enregistrement courant
|
||||
$config=$em->getRepository($this->entity)->find($id);
|
||||
if(!$config->isRequired()) {
|
||||
$config->setValue("");
|
||||
$em->getManager()->flush();
|
||||
}
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
|
||||
public function logo($access): Response
|
||||
{
|
||||
return $this->render($this->twig.'logo.html.twig');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user