我刚开始使用Slim框架(http://www.slimframework.com/);我从相同的站点下载了zip文件,其中有一些示例并测试它我尝试了localhost / proj1并且它可以正常工作,但是当我尝试localhost / proj1 / index.php / delete时它会让我给出404错误,尽管它是应该回应#34;这是一条DELETE路线",如果我是对的!
$app->delete(
'/delete',
function () {
echo 'This is a DELETE route';
}
);
我做错了吗?
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]
答案 0 :(得分:2)
您应该将浏览器指向: -
localhost/proj1/delete
你的代码应该是: -
$app->get('/delete',
function(){
echo 'This is a DELETE route';
}
);
由于您的浏览器会发送“获取”信息。请求,而非删除'请求。如果您的浏览器发送了“删除”信息,原始代码就可以使用。请求,但它不能。请参阅this answer以了解原因。