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
| <?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;
class DefaultController extends Controller {
public function indexAction() {
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() {
$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) {
return $this->render('SymfonyCapsuleCapsuleBundle:Default:detail.html.twig', array(
'capsule' => $capsule,
));
}
public function ajouterAction() {
$em = $this->getDoctrine()->getEntityManager();
$a = new Capsule();
$form = $this->createForm(new CapsuleType(), $a);
$request = $this->getRequest();
if ($request->isMethod('POST')) {
$form->bindRequest($request);
if ($form->isValid()) {
$maison = $em->getRepository('SymfonyCapsuleCapsuleBundle:Maison')->find($a->getIdMaison());
$a->setIdMaison($maison);
//$a = $form->getData();
//var_dump($form->getData());
//exit;
//$a->setIdMaison($) == '';
$em->persist($a);
$em->flush();
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()
{
//$em = $this->getDoctrine()->getEntityManager();
$user=$this->getRequest()->getUser();
$id=$this->get($user);
return new response($id);
//$profil = $em->getRepository("SymfonyCapsuleCapsuleBundle:Adherent")->find($id);
return $this->render('SymfonyCapsuleCapsuleBundle:Default:profil.html.twig', array(
// 'profil' => $profil,
));
}
} |