Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

213
Vistas
How to receive a message, instead of throwing exception in Symfony?

I have a function for displaying the user bag in e-commenrce website. When the user bag is empty, it throws the following exception:

if (!$bag) {
    throw  new NotFoundHttpException();
}

How can i display a message like "Your bag is empty", or something, instead of throwing an

404 Not Found - NotFoundHttpException

Thanks in advance !

8 months ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

There are a lot of ways to do it.

You can use flash messages or even render twig template that will inform about empty bag.

Or you can pass to template the parameter that will say that bag is empty and then you can use that parameter in the template.

Or you can check $bag object right in twig template like

{% if bag is null %}Your bag is empty{% endif %}

8 months ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.