[Solved] How to instruct Slim 3 not to halt on unmatched routes


#1

Hey there!

I’m trying to integrate Slim 3 with a WordPress website, where I’m essentially running Slim before/in front of the main website (using the auto_prepend_file rule in the .htaccess file to execute Slim before WP is loaded).

Whenever a WP page is requested, I would like to run some tests in Slim and if the tests pass, silently go away and allow the WP application to process as usual. For some routes such as /api/*, I would like to have slim take over and function as normal.

The problem seems to be that if a route is not matched, a 404 page is shown and that automatically halts the request.

Is there any way to instruct Slim 3 not to halt the page execution is a route is not found? I tried to follow the answers on this post for Slim 2 but not able to make much progress with Slim 3.

Any help would be much appreciated.

Thanks!
Ananda


#2

They way I’ve seen this handled by others is only when you can determine which app should handle the request by the route itself. For example if all of the /api/* routes and /slim/* routes are handled by Slim then you can point them to Slim’s front controller, otherwise they get sent to WP’s front controller.

Otherwise, I can’t think of how you might handle that, though there might be ways. However it was actually done it would likely involve writing your own 404 Not Found Handler in Slim which would somehow pass along the request to WP, perhaps just by including WP’s front controller?.?


#3

Thanks @tflight for your response. I did a little digging around and found that the run() method in Slim\App.php accepts the $silent parameter. As the name suggests, passing true makes Slim run silently without halting execution or sending any output. This solved my problem!