Slim error BadRouteException

2

Checking the logs on the server 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 you have actually searched it was unclear what might cause this type of 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) {});
    
asked by anonymous 22.08.2017 / 10:41

1 answer

0

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 should come before dynamics

    
26.08.2017 / 05:05