php – Slim error BadRouteException

Question:

Checking the logs on the server I found the following error:

Slim Application Error:
Type: FastRoute\BadRouteException
Message: Static route "/client/schedules" is shadowed by previously defined variable route "/client/([^/]+)" for method "GET"

and even though I've done some research it's not really clear what can cause such an exception.

Organization of routes, if relevant:

    #Client routes
    $app->get('/client[/{id}]', function(Request $request, Response $response, $args){});
    $app->post('/client', function(Request $request, Response $response, $args){});
    $app->delete('/client', function(Request $request, Response $response, $args){});

    #Credit routes
    $app->post('/credits/buy', function(Request $request, Response $response, $args){});

    #deliveryman routes
    $app->post('/deliveryman', function(Request $request, Response $response, $args){});

    #Moip routes
    $app->get('/teste', function (Request $request, Response $response, $args){});

    #Plan routes
    $app->get('/plans', function(Request $request, Response $response, $args){});
    $app->post('/plans', function(Request $request, Response $response, $args){});
    $app->post('/plans/sign', function(Request $request, Response $response, $args){});

    #Responses routes
    $app->get('/error', function(Request $request, Response $response, $args){});

    #Schedule routes
    $app->get('/schedule', function (Request $request, Response $response, $args ){});
    $app->post('/schedule/deny/{id}', function(Request $request, Response $response, $args){});
    $app->post('/schedule/cancel/{id}', function(Request $request,Response $response, $args){ });
    $app->post('/schedule/accept/{id}', function(Request $request,Response $response, $args){});
    $app->post('/schedule/accept', function(Request $request,Response $response, $args){});
    //client
    $app->post('/schedule', function (Request $request, Response $response, $args ){});

    #Users routes
    $app->get('/login/{type}', function (\Slim\Http\Request $request, \Slim\Http\Response $response, $args) {});
    $app->get('/logout', function (\Slim\Http\Request $request, \Slim\Http\Response $response, $args) {});

Answer:

The solution to the problem was to reorder the routes, apparently my error was due to the order of the routes in the example file:

$app->post('/plans{id}', function(Request $request, Response $response, $args){});
$app->post('/plans/sign', function(Request $request, Response $response, $args){});

The correct is

$app->post('/plans/sign', function(Request $request, Response $response, $args){});
$app->post('/plans{id}', function(Request $request, Response $response, $args){});

Static route must come before dynamic

Scroll to Top
AllEscort