Slim error Badrouteexception

Asked

Viewed 488 times

3

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’ve researched it really hasn’t become clear what can cause this kind of exception.

Route organisation, 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) {});
  • 2

    You’re accessing a route /client/schedules statically, while there is already a dynamic route definition for /client[/{id}].

  • apparently it had a duplicate route, but it was worth =D

  • If my comment helped you answer, I’ll come up with an answer. If not, leave your answer as to how you solved the problem, it may help others in the future.

  • Yes I’m sorry, I had completely forgotten about the post, because well the solution was the following there was a static get route running after the dynamic route. This way we only needed to reorder, adding the static route before the dynamic route.

1 answer

1

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.