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 08:19] 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 168: | Ligne 168: | ||
| ... | ... | ||
| | | ||
| + | $modalBarge = $this-> | ||
| + | ' | ||
| + | ' | ||
| + | )); | ||
| + | | ||
| $json_array = array( | $json_array = array( | ||
| - | ' | + | ' |
| + | ' | ||
| ); | ); | ||
| Ligne 218: | Ligne 224: | ||
| ---- | ---- | ||
| - | ===== Exemple d'un contrôleur CRUD ===== | ||
| - | <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-> | ||
| - | } | ||
| - | |||
| - | } | ||
| - | </ | ||