Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

497
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!