Slim Framework always return 404 Error

后端 未结 8 424
独厮守ぢ
独厮守ぢ 2021-02-01 04:27

These days i\'m using Slim Framework as my simplest tool to develop the php web api. Using these two articles:

  • Coenraets
  • CodingThis
8条回答
  •  既然无缘
    2021-02-01 05:09

    I think your problem is at the "Resource parser" because you are no defining $id parameter at the request so, please, try this:

    //1. Require Slim
    require('Slim/Slim.php');
    
    //2. Instantiate Slim
    $app = new Slim();
    
    //3. Define routes
    $app->get('/books/:id/', function ($id) {
        echo json_encode( getBook($id) );
    });
    
    // some stuff
    $app->run();
    

    Please, tell us if it's ok

提交回复
热议问题