I have problem when my request (POST method) has no an appropriate route.
<h1>Slim Application Error</h1>
<p>The application could not run because of the following error:</p>
<h2>Details</h2>
<div>
<strong>Type:</strong> Error
</div>
<div>
<strong>Message:</strong> Call to a member function getName() on null
</div>
<div>
<strong>File:</strong> C:\xampp\htdocs\myapp\app\Middleware\NavigationMiddleware.php
</div>
NavigationMiddleware.php
[...]
$currentRouteName = $request->getAttribute('route')->getName();
[...]
You need to use:
$app = new Slim\App([
'settings' => [
'determineRouteBeforeAppMiddleware' => true,
]
]);
I use it. I see this error when route not exist for request url.
So what is the problem?
http://lwiwala.ct8.pl/asdf I would like to show 404 page
Just check for null before calling getName()
Most helpful comment
Just check for
nullbefore callinggetName()