In one of the projects I’m working a custom 404 page needs to be implemented for each bundle.
Inside the documentation there is nothing mentioned for such functionality.
I was discussing the issue with some colleagues and was told that it has to use the kernel.exception event, alas this one lacks the information which bundle is calling it.
IMHO this should be fixed by applying a patch to symfony router component which would allow the developer to specify catch-all route which could handle the case further.
Another option would be to change the behavior of the RouterInterface::match method to return consistent output containing the matched path and the bundle which matched it. Currently this is not possible, because it throws an exception if match fails and does not give you any information at all, while it could.
For example, I have an ApiBundle which is defined to handle urls starting with “/api”. Currently the only way to handle this one and set custom 404 page is to get the request at the time of the kernel.exception and preg_match() the url. This, however, is hardcoding that should be avoided as the bundle should not have such knowledge – it is defined under the app/config/routing file.
What’s your opinion?
I would appreciate any other workarounds as well.
I’ve ended up implementing my custom ExceptionController which dispatches an event I called ‘ourCompany.exception_response’.