dsd57259 2016-09-22 16:53
浏览 95
已采纳

为slim路由器添加基本URL路径

I have a bunch of routes and they all start with /api/2.01.

How can I add it once so it applies to all routes. Slim Framework Base URL asks the same question, but I believe provides an outdated answer.

PS. If instead of asking a new question, should I have instead somehow tagged the post which I believe is dated to be reviewed or something?

$app = new \Slim\Slim();
$app->post('/api/2.01/books', function () {
    //Create books
});
$app->get('/api/2.01/books', function () {
    //getbook
});
$app->get('/api/2.01/books/{id}', function () {
    //Get book
});
$app->delete('/api/2.01/books/{id}', function () {
    //Create book
});
  • 写回答

1条回答

  • doty58493 2016-09-22 20:07
    关注

    If you are using Slim v2.0, you can do somtehing like:

    // API group
    $app->group('/api', function () use ($app) {
    
    // Library group
    $app->group('/library', function () use ($app) {
    
        // Get book with ID
        $app->get('/books/:id', function ($id) {
    
        });
    
        // Update book with ID
        $app->put('/books/:id', function ($id) {
    
        });
    
        // Delete book with ID
        $app->delete('/books/:id', function ($id) {
    
        });
    
    });
    

    as specified in the docs: http://docs.slimframework.com/routing/groups/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案