Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
|
symfony_4:fonctionnement:les_controleurs_preparation_des_donnees [2018/10/19 07:58] julien.guerin |
symfony_4:fonctionnement:les_controleurs_preparation_des_donnees [2019/12/08 07:41] (Version actuelle) |
||
|---|---|---|---|
| Ligne 26: | Ligne 26: | ||
| * index (listing, page d' | * index (listing, page d' | ||
| * add | * add | ||
| - | * edit | + | * update |
| * delete | * delete | ||
| Ligne 117: | Ligne 117: | ||
| public function edit(Request $request, SWFile $SWFile){ ... } | public function edit(Request $request, SWFile $SWFile){ ... } | ||
| </ | </ | ||
| + | |||
| ---- | ---- | ||
| + | |||
| ==== Retours ==== | ==== Retours ==== | ||
| Ligne 126: | Ligne 128: | ||
| * Réponse en JSON (pour l' | * Réponse en JSON (pour l' | ||
| * Re-direction vers une route spécifique | * Re-direction vers une route spécifique | ||
| - | * Un code HTML ( 200, 404, 500 ) | + | |
| + | ---- | ||
| === Affichage d'une vue (TWIG) === | === Affichage d'une vue (TWIG) === | ||
| Ligne 152: | Ligne 155: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | ---- | ||
| === Envoi en AJAX === | === Envoi en AJAX === | ||
| Ligne 163: | Ligne 168: | ||
| ... | ... | ||
| | | ||
| + | $modalBarge = $this-> | ||
| + | ' | ||
| + | ' | ||
| + | )); | ||
| + | | ||
| $json_array = array( | $json_array = array( | ||
| - | ' | + | ' |
| + | ' | ||
| ); | ); | ||
| Ligne 171: | Ligne 182: | ||
| </ | </ | ||
| + | ---- | ||
| === Redirection vers une route === | === Redirection vers une route === | ||
| Ligne 209: | Ligne 221: | ||
| } | } | ||
| </ | </ | ||
| - | |||
| - | |||
| - | === Code HTML === | ||
| - | |||
| ---- | ---- | ||
| - | ===== Exemple ===== | ||
| - | <code PHP> | ||
| - | <?php | ||
| - | namespace App\Controller; | ||
| - | |||
| - | use App\Entity\SWFile; | ||
| - | use App\Form\SWFileType; | ||
| - | use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; | ||
| - | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
| - | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
| - | use Symfony\Component\HttpFoundation\Response; | ||
| - | use Symfony\Component\HttpFoundation\Request; | ||
| - | |||
| - | class SWFileController extends Controller | ||
| - | { | ||
| - | /** | ||
| - | * Display SWFile list in tab | ||
| - | * | ||
| - | * @Route("/ | ||
| - | | ||
| - | * @IsGranted(" | ||
| - | | ||
| - | * @param Request $request | ||
| - | * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response | ||
| - | */ | ||
| - | public function index(Request $request) | ||
| - | { | ||
| - | $manager = $this-> | ||
| - | |||
| - | $tabSWFile = $manager-> | ||
| - | |||
| - | return $this-> | ||
| - | ' | ||
| - | )); | ||
| - | } | ||
| - | |||
| - | /** | ||
| - | * Add a SWFile | ||
| - | * | ||
| - | * @Route("/ | ||
| - | * | ||
| - | * @IsGranted(" | ||
| - | * | ||
| - | * @param Request $request | ||
| - | * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response | ||
| - | */ | ||
| - | public function add( Request $request ) | ||
| - | { | ||
| - | $SWFile = new SWFile(); | ||
| - | $form = $this-> | ||
| - | |||
| - | $form-> | ||
| - | |||
| - | if ($form-> | ||
| - | // $form-> | ||
| - | // but, the original `$task` variable has also been updated | ||
| - | $SWFile = $form-> | ||
| - | |||
| - | //MAJ des champs non disponibles sur le formulaire | ||
| - | $SWFile-> | ||
| - | $SWFile-> | ||
| - | |||
| - | // | ||
| - | $manager = $this-> | ||
| - | $manager-> | ||
| - | $manager-> | ||
| - | |||
| - | return $this-> | ||
| - | } | ||
| - | |||
| - | return $this-> | ||
| - | ' | ||
| - | )); | ||
| - | } | ||
| - | |||
| - | /** | ||
| - | * Edit a SWFile | ||
| - | * | ||
| - | * @Route("/ | ||
| - | * | ||
| - | * @IsGranted(" | ||
| - | * | ||
| - | * @param Request $request | ||
| - | * @param SWFile $SWFile | ||
| - | * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response | ||
| - | */ | ||
| - | public function edit(Request $request, SWFile $SWFile) | ||
| - | { | ||
| - | $form = $this-> | ||
| - | |||
| - | $form-> | ||
| - | |||
| - | if ($form-> | ||
| - | // $form-> | ||
| - | // but, the original `$task` variable has also been updated | ||
| - | $SWFile = $form-> | ||
| - | |||
| - | //MAJ des champs non disponibles sur le formulaire | ||
| - | $SWFile-> | ||
| - | $SWFile-> | ||
| - | |||
| - | // | ||
| - | $manager = $this-> | ||
| - | $manager-> | ||
| - | $manager-> | ||
| - | |||
| - | return $this-> | ||
| - | } | ||
| - | |||
| - | return $this-> | ||
| - | ' | ||
| - | )); | ||
| - | } | ||
| - | |||
| - | /** | ||
| - | * Delete a SWFile (not the file, just the database slot | ||
| - | * | ||
| - | * @Route("/ | ||
| - | * | ||
| - | * @IsGranted(" | ||
| - | * | ||
| - | * @param Request $request | ||
| - | * @param SWFile $SWFile | ||
| - | * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response | ||
| - | */ | ||
| - | public function delete(Request $request, SWFile $SWFile) | ||
| - | { | ||
| - | $manager = $this-> | ||
| - | |||
| - | //retrait du SWFile | ||
| - | $manager-> | ||
| - | $manager-> | ||
| - | |||
| - | return $this-> | ||
| - | } | ||
| - | |||
| - | } | ||
| - | </ | ||