Ver Mensaje Individual
  #7 (permalink)  
Antiguo 12/11/2013, 16:48
Avatar de hhs
hhs
Colaborador
 
Fecha de Ingreso: junio-2013
Ubicación: México
Mensajes: 2.995
Antigüedad: 10 años, 10 meses
Puntos: 379
Respuesta: Capturar Excepciones

Cita:
Iniciado por ana_arcon Ver Mensaje
try {
...
throw $this->createNotFoundException('La asignacion ya existe, seleccione otro caso');
$em->flush();

return $this->redirect($this->generateUrl('diagnostico'));

} catch(\Exception $e){

echo $e-> getMessage();
return $this ->redirect($this->generateUrl('diagnostico_new'));
}
Puedes usar un Flash Message:
Código PHP:
Ver original
  1. try {
  2.             ...
  3.             throw new Exception('La asignacion ya existe, seleccione otro caso');
  4.             $em->flush();
  5.            
  6.             return $this->redirect($this->generateUrl('diagnostico'));
  7.  
  8.  } catch(\Exception $e){
  9.               $this->get('session')->setFlash('error', $e->getMessage());
  10. }

Y en tu plantilla mostrar el error con los estilos que requieres
Código HTML:
Ver original
  1. {% for flashMessage in app.session.flashbag.get('error') %}
  2.     <div class="error">
  3.         {{ flashMessage }}
  4.     </div>
  5. {% endfor %}
__________________
Saludos
About me
Laraveles
A class should have only one reason to change.