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
| public function ajouterAction()
{
$msg= "Ajouter Palmares";
$em = $this->getDoctrine()->getManager();
$palma = new Palmares();
$form = $this->createForm(new PalmaresType,$palma);
$request = $this->getRequest();
$entity = $em->getRepository('CrudBundle:Palmares')->findAll();
foreach ($entity as $entits)
{
if( file_exists( $this->get('kernel')->getRootDir().$entits->getId().'.txt')){ // si le fichier txt existe
$fichi = fopen( $this->get('kernel')->getRootDir().$entits->getId().'.txt', 'r');
$contenu[$entits->getId()] = fgets($fichi);
}
}
fclose($fichi);
if($request->getMethod()=='POST') {
$form->handleRequest($request);
if ($form->isValid()) {
$palma->upload();
$em->persist($palma);
$em->flush();
$msg="Palmares ajoutée avec success :)";
}
}
return $this->render('CrudBundle:Palmares:ajouter.html.twig',array(
'form'=>$form->createView(),
'msg'=>$msg,
'contenu' => $contenu
)
);
} |