• Empleos
  • Sobre nosotros
  • Empleos
    • Inicio
    • Empleos
    • Cursos y retos
  • Empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

441
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 3 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 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda