Salut,
je suis un débutant en symfony et je veut faire un CRUD avec modale j'arrive a faire l'ajout mais pour la modifier j'ai un probleme.il me semble qu'il faut de javascript pour faire la redirection je sais pas !!!!
voici le code de mon controleur
<?php
namespace App\Controller;
use App\Entity\LangueMatiere;
use App\Form\LangueMatiereType;
use App\Repository\LangueMatiereRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/langue")
*/
class LangueMatiereController extends AbstractController
{
/**
* @Route("/", name="langue_matiere_index", methods={"GET"})
*/
public function index(LangueMatiereRepository $langueMatiereRepository): Response
{
return $this->render('langue_matiere/index.html.twig', [
'langue_matieres' => $langueMatiereRepository->findAll(),
]);
}
/**
* @Route("/new", name="langue_matiere_new", methods={"GET","POST"})
*/
public function new(Request $request): Response
{
$langueMatiere = new LangueMatiere();
$form = $this->createForm(LangueMatiereType::class, $langueMatiere);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($langueMatiere);
$entityManager->flush();
return new Response('success');
return $this->redirectToRoute('langue_matiere_index');
}
return $this->render('langue_matiere/new.html.twig', [
'langue_matiere' => $langueMatiere,
'form' => $form->createView(),
]);
}
/**
* @Route("/{id}", name="langue_matiere_show", methods={"GET"})
*/
public function show(LangueMatiere $langueMatiere): Response
{
return $this->render('langue_matiere/show.html.twig', [
'langue_matiere' => $langueMatiere,
]);
}
/**
* @Route("/{id}/edit", name="langue_matiere_edit", methods={"GET","POST"})
*/
public function edit(Request $request, LangueMatiere $langueMatiere): Response
{
$form = $this->createForm(LangueMatiereType::class, $langueMatiere);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('langue_matiere_index');
}
return $this->render('langue_matiere/edit.html.twig', [
'langue_matiere' => $langueMatiere,
'form' => $form->createView(),
]);
}
/**
* @Route("/{id}", name="langue_matiere_delete", methods={"DELETE"})
*/
public function delete(Request $request, LangueMatiere $langueMatiere): Response
{
if ($this->isCsrfTokenValid('delete'.$langueMatiere->getId(), $request->request->get('_token'))) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($langueMatiere);
$entityManager->flush();
}
return $this->redirectToRoute('langue_matiere_index');
}
}
voici le code de template index.html.twig
{% extends 'base.html.twig' %}
{% block title %}Liste Langue Matiere {% endblock %}
{% block body %}
<h1>Liste Langue Matiere </h1>
{% for message in app.flashes('info') %}
<div class="alert alert-success">{{ message }}</div>
{% endfor %}
{{ render(controller(
'App\\Controller\\LangueMatiereController::new'))}}
{#<td><a>
<button class="btn btn-success" data-toggle="modal" data-target="#modalAjoutForm"><span
class="glyphicon glyphicon-plus"></span></button>
</a></td>#}
<table class="table">
<thead>
<tr>
<th>Langue Matière en Français</th>
<th>Langue Matière en Arabe</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{% for langue_matiere in langue_matieres %}
<tr>
<td>{{ langue_matiere.libelleLangueFe }}</td>
<td>{{ langue_matiere.libelleLangueAr }}</td>
<td><a>
<button class="btn btn-primary" data-toggle="modal" data-target="#myModal{{ langue_matiere.id }}"><span
class="glyphicon glyphicon-info-sign"></span></button>
</a></td> {#<td><a href="{{ path('langue_matiere_edit', {'id': langue_matiere.id}) }}">
<button class="btn btn-success"><span class="glyphicon glyphicon-pencil"></span></button>
</a>
</td>#}
<a href="" class="tooltip-test" name="_method" value="DELETE" data-placement="top" title="" data-original-title="Supprimer" data-toggle="modal" data-target="#deleteModal{{ langue_matiere.id }}"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span> </a>
<td>
{{ render(controller(
'App\\Controller\\LangueMatiereController::edit',{'id':langue_matiere.id}))}}
</td>
<td> {{ include('langue_matiere/_delete_form.html.twig') }} </td>
</tr>
<td>
<div class="modal fade" id="deleteModal{{ langue_matiere.id }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<br><br><br><br>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Comfirmation de suppression :</h4>
</div>
<div class="modal-body" >
<p><span>Voulez-vous vraiment supprimer <a href="#"></a> {{ langue_matiere.libelleLangueAr }}? </span></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default " data-dismiss="modal">Annuler</button>
<a href="{{ path('langue_matiere_delete', {'id': langue_matiere.id}) }}" data-toggle="modal" class="btn btn-danger" id="DELETE" >Supprimer</a>
</div>
</div>
</div>
</div>
</td>
<div class="modal fade" id="myModal{{ langue_matiere.id }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<br><br><br><br>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel"> Détail :</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-lg-6">
<ul>
<li><strong>Langue matière en Français: </strong> {{ langue_matiere.libelleLangueFe }}</li> <br>
<li><strong>Langue matière en Arabe: </strong> {{ langue_matiere.libelleLangueAr }}</li> <br>
</ul>
</div>
<div class="col-lg-6">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Fermer</button>
</div>
</div>
</div>
</div>
{% else %}
<tr>
<td colspan="4">Pas d'enregistrement</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
quand j'appuis sur modifier la formulaire sera bien rempli mais quand je confirme la modification j'ai l'erreur suivant:
No route found for "POST /langue/": Method Not Allowed (Allow: GET)
Aidez moi SVP