我对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
正在运行,没有任何问题,
答案 0 :(得分:1)
没有找到它,因为Slim 3使用{id}
作为占位符,而不像Slim 2那样使用:id
。因此代码将是
$this->get('/books/{id}', function ($request, $response, $args) {
...
});
中找到