Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

502
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 !

over 4 years 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 %}

over 4 years 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 vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda