Slim: getName() for not exists route

Created on 17 Jul 2016  路  5Comments  路  Source: slimphp/Slim

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();
[...]

Most helpful comment

Just check for null before calling getName()

All 5 comments

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()

Was this page helpful?
0 / 5 - 0 ratings

Related issues

geggleto picture geggleto  路  4Comments

alffonsse picture alffonsse  路  4Comments

jwyuen picture jwyuen  路  5Comments

JamesTheHacker picture JamesTheHacker  路  3Comments

codeguy picture codeguy  路  3Comments