1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
| <?php
namespace SymfonyCapsule\CapsuleBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use SymfonyCapsule\CapsuleBundle\Entity\Adherent;
use SymfonyCapsule\CapsuleBundle\Form\AdherentType;
use SymfonyCapsule\CapsuleBundle\Entity\Capsule;
use SymfonyCapsule\CapsuleBundle\Form\CapsuleType;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
class DefaultController extends Controller {
public function indexAction() {
//Acceuil
return $this->render('SymfonyCapsuleCapsuleBundle:Default:index.html.twig');
}
public function inscriptionAction() {
$em = $this->getDoctrine()->getEntityManager();
$a = new Adherent();
$form = $this->createForm(new AdherentType(), $a);
$request = $this->getRequest();
if ($request->isMethod('POST')) {
$form->bindRequest($request);
if ($form->isValid()) {
$a = $form->getData();
$em->persist($a);
$em->flush();
return $this->redirect($this->generateUrl("symfony_capsule_capsule_homepage"));
}
}
return $this->render('SymfonyCapsuleCapsuleBundle:Default:inscription.html.twig', array(
'form' => $form->createView(),
));
}
public function voirAction() {
//affichage de toutes les capsules
$em = $this->getDoctrine()->getEntityManager();
$capsule = $em->getRepository("SymfonyCapsuleCapsuleBundle:Capsule")->findAll();
return $this->render('SymfonyCapsuleCapsuleBundle:Default:voir.html.twig', array(
'capsules' => $capsule,
));
}
public function detailAction(Capsule $capsule) {
//detail de la capsule selectionné
return $this->render('SymfonyCapsuleCapsuleBundle:Default:detail.html.twig', array(
'capsule' => $capsule,
));
}
public function modifier_profilAction() {
$em = $this->getDoctrine()->getEntityManager();
// récupération de l'utilisateur
$adherent = $this->get('security.context')->getToken()->getUser();
// création d'un objet formulaire suivant un modèle type et préchargé avec les données de notre utilisateur
$editForm = $this->createForm(new AdherentType(), $adherent);
// récupération des données du formulaire (entre autres)
$request = $this->getRequest();
//si la methode est un post alors
if ($request->isMethod('POST')) {
// hydratation de l'utilisateur avec TOUTES les données issues du formulaire
$editForm->bindRequest($request);
//si le formulaire est valide alors
if ($editForm->isValid()) {
//on persist l'envoi du formulaire et on flush vers la base de donnée
$em->persist($adherent);
$em->flush();
//redirection vers l'index
return $this->redirect($this->generateUrl("symfony_capsule_capsule_profil"));
}
}
}
public function ajouterAction() {
//On recupère la classe EntityManager
$em = $this->getDoctrine()->getEntityManager();
//nouvel objet de capsule
$a = new Capsule();
//creation du formulaire CapsuleType
$form = $this->createForm(new CapsuleType(), $a);
//on recupère la fonction getRequest de la classe Controller
$request = $this->getRequest();
//si la methode est un post alors
if ($request->isMethod('POST')) {
$form->bindRequest($request);
//si le formulaire est valide alors
if ($form->isValid()) {
$maison = $em->getRepository('SymfonyCapsuleCapsuleBundle:Maison')->find($a->getIdMaison());
$a->setIdMaison($maison);
/*
* affiche les valeurs des variables
* $a = $form->getData();
* var_dump($form->getData());
* exit;
*/
//on persist l'envoi du formulaire et on flush vers la base de donnée
$em->persist($a);
$em->flush();
//redirection vers l'index
return $this->redirect($this->generateUrl("symfony_capsule_capsule_index"));
}
}
return $this->render('SymfonyCapsuleCapsuleBundle:Default:ajouter.html.twig', array(
'form' => $form->createView(),
));
}
public function loginAction() {
$request = $this->getRequest();
$session = $request->getSession();
// get the login error if there is one
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
$error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
} else {
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
}
return $this->render('SymfonyCapsuleCapsuleBundle:Default:login.html.twig', array(
// last username entered by the user
'last_username' => $session->get(SecurityContext::LAST_USERNAME),
'error' => $error,
));
}
public function profilAction() {
$utilisateur = $this->get('security.context')->getToken()->getUser();
return $this->render('SymfonyCapsuleCapsuleBundle:Default:profil.html.twig', array(
'utilisateur' => $utilisateur,
));
}
} |
Partager