Slimphp 3嵌套组不起作用

时间:2017-05-17 07:12:28

标签: php slim

我对slimphp路由器有一点问题:

$app->group('/api', function () use ($app) {

    // Library group
    $this->group('/library', function () use ($app) {

        // Get book with ID
        $this->get('/books/:id', function ($req, $res) {
            echo "books";
        });

        // Update book with ID
        $this->put('/books/:id', function ($req, $res) {

        });

        // Delete book with ID
        $this->delete('/books/:id', function ($req, $res) {

        });

    });

});

GET发送到/ api / library / books / 1会给我一个Page not found错误,问题出在哪里。

编辑:

.htaccess

RewriteEngine On

# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
# RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

PS:一个简单的app->get正在运行,没有任何问题,

1 个答案:

答案 0 :(得分:1)

没有找到它,因为Slim 3使用{id}作为占位符,而不像Slim 2那样使用:id。因此代码将是

$this->get('/books/{id}', function ($request, $response, $args) {
    ...
});

Slim 3 Documentation for Route Placeholders

中找到