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
| <?php
namespace CrudBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use CrudBundle\Entity\Actualite;
use CrudBundle\Form\ActualiteType;
use Symfony\Component\HttpFoundation\Response;
class ActualiteController extends Controller
{
public function ajouterAction()
{
$msg= "Ajouter Actualite";
$em = $this->getDoctrine()->getManager();
$arti = new Actualite();
$form = $this->createForm(new ActualiteType,$arti);
$request = $this->getRequest();
if($request->getMethod()=='POST') {
$form->handleRequest($request);
if ($form->isValid()) {
$arti->upload();
$em->persist($arti);
$em->flush();
$msg="Actualite ajoutée avec success ";
}
}
return $this->render('CrudBundle:Actualite:ajouter.html.twig',array(
'form'=>$form->createView(),
'msg'=>$msg
)
);
}
public function presentationAction($id)
{
$em = $this->getDoctrine()->getManager();
$actu = $em->getRepository('CrudBundle:Actualite')->find($id);
if (!$actu) return $this->render('CrudBundle:Default:erreur.html.twig');
return $this->render('CrudBundle:Actualite:presentation.html.twig', array('actua' => $actu ));
}
public function afficherAction() {
$em = $this->getDoctrine()->getManager();
$findactu = $em->getRepository('CrudBundle:Actualite')->findBy(array(), array('id'=>'desc'));
$actu = $this->get('knp_paginator')->paginate($findactu,$this->get('request')->query->get('page', 1),9);
return $this->render('CrudBundle:Actualite:afficher.html.twig',array('actus'=>$actu));
}
public function afficherindexAction() {
$em = $this->getDoctrine()->getManager();
$actu = $em->getRepository('CrudBundle:Actualite')->findBy(array(), array('id'=>'desc'),4);
$artis = $em->getRepository('CrudBundle:Article')->findBy(array(), array('id'=>'desc'),3);
// Match terminé?
$match = $em->getRepository('CrudBundle:Matche')->findBy(array(), array('id'=>'desc'),1);
$resultat = $em->getRepository('CrudBundle:Matche')->findOneBy(array('active' => 1), array('id'=>'desc'));
$list = $em->getRepository('CrudBundle:Matche')->findBy(array(), array('id'=>'desc'),6);
$joueur = $em->getRepository('CrudBundle:Joueur')->findBy(array(), array('id'=>'desc'),6);
$photo = $em->getRepository('CrudBundle:Photo')->findBy(array(), array('id'=>'desc'),6);
$interview = $em->getRepository('CrudBundle:Interview')->findBy(array(), array('id'=>'desc'),1);
$video = $em->getRepository('CrudBundle:Video')->findBy(array(), array('id'=>'desc'),3);
return $this->render('CrudBundle:Default:page.html.twig',array(
'actus'=>$actu,
'arti' => $artis,
'matc' => $match,
'resul' => $resultat,
'joue' => $joueur,
'phot' => $photo,
'inter' => $interview,
'vid' => $video,
'lis' => $list
));
}
public function listAction() {
$em = $this->getDoctrine()->getManager();
//$findarti = $em->getRepository('CrudBundle:Actualite')->findAll();
$findarti = $em->getRepository('CrudBundle:Actualite')->findBy(array(), array('id'=>'desc'));
$arti = $this->get('knp_paginator')->paginate($findarti,$this->get('request')->query->get('page', 1),3);
return $this->render('CrudBundle:Actualite:list.html.twig',array('arti'=>$arti));
}
public function modifierAction($id)
{
$msg= "Modifier Actualite";
$em = $this->getDoctrine()->getManager();
$arti = $em->getRepository('CrudBundle:Actualite')->find($id);
$form = $this->createForm(new ActualiteType,$arti);
$request = $this->getRequest();
if($request->getMethod()=='POST') {
$form->handleRequest($request);
if ($form->isValid()) {
$arti->upload();
$em->flush();
$msg="Actualite Modifiée avec success ";
}
}
return $this->render('CrudBundle:Actualite:modifier.html.twig',array(
'form'=>$form->createView(),
'msg'=>$msg
)
);
}
public function supprimerAction($id) {
$em=$this->getDoctrine()->getManager();
$arti = $em->find('CrudBundle:Actualite',$id);
if (!$arti) return $this->render('CrudBundle:Default:erreur.html.twig');
$em->remove($arti);
$em->flush();
return new Response("Actualite supprimée avec succes");
}
} |
Partager