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 !
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 %}