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
| <?php
namespace Qcm\SalleTpBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Qcm\SalleTpBundle\Entity\Salle;
use Symfony\Component\HttpFoundation\Request;
class SalleController extends Controller
{
public function indexAction()
{
$session = $this->get('session');
if ($session->has('nbreFois'))
$session->set('nbreFois', $session->get('nbreFois')+1);
else
$session->set('nbreFois', 1);
\Doctrine\Common\Util\Debug::dump($this->get('session')->getFlashBag()->get('infoAjout'));//pour le debugage
return $this->render('QcmSalleTpBundle:Salle:index.html.twig',
array('nbreFois' => $session->get('nbreFois')));
}
public function voirSalleAction($id)
{
$repository = $this->getDoctrine()->getManager()
->getRepository('QcmSalleTpBundle:Salle');
$salle = $repository->find($id);
if($salle === null)
throw $this->createNotFoundException('Salle[id='.$id.'] inexistante');
return $this->render('QcmSalleTpBundle:Salle:voirSalle.html.twig',
array('nomSalle' => $salle->__toString()));
}
public function ajouterSalleAction(Request $request) {
$salle = new Salle;
$form = $this->createFormBuilder($salle)
->add('batiment', 'text')
->add('etage', 'text')
->add('numero', 'text')
->add('envoyer', 'submit')
->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
{
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($salle);
$entityManager->flush();
$this->get('session')->getFlashBag()->add('infoAjout',
'nouvelle salle '.$salle->__toString());
$url = $this->generateUrl('qcm_salle_tp_accueil');
/*\Doctrine\Common\Util\Debug::dump($this->get('session')->getFlashBag());
return new Response('<html><body></body></html>');*/
return $this->redirect($url);
}
}
return $this->render('QcmSalleTpBundle:Salle:ajouterSalle.html.twig',
array('form' => $form->createView()));
}
} |