We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Anonymous function for notFound in router

As I have my own error handler implemented, I'd like to an option for using anonymous functions in $router->notFound() as it's unnecessary to implement an extra controller. Is there any way to use something like this?

$router->notFound(function() {
    throw new NotFoundException();
});


32.2k
Accepted
answer

Hi @mohahn it's not possible today. As you can see in the source code.

But you can create your own router or better yet create a NFR in github repo

Good luck