我使用IIS 6.2在Windows Server 2012机器上设置了Slim框架,并且Slim php框架几乎可以工作。Slim 正确处理没有参数的 url,如下所示:
$app->get('/books', function () {
echo "Yay book!";
});
但是一旦我们添加了 url 参数(请参阅: http://docs.slimframework.com/routing/params/),如下所示:
$app->get('/books/:one/:two', function ($one, $two) {
echo "The first parameter is " . $one;
echo "The second parameter is " . $two;
});
它失败并显示 404。我一直在挖掘我的 web.config 文件,剖析它后,它对我来说仍然正确,这里是:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="slim" patternSyntax="Wildcard">
<match url="*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
进一步说明,slim api 位于 web 根目录/api 的子目录中,这就是这个 web.config 所在的位置。
显然,
SLIM 将他们的请求的工作方式从版本 2 更改为版本 3。编写该端点的正确方法是这样的/books
:
$app->get('/books/{one}/{two}', function ($request, $response) {
echo "The first parameter is " . $request->getAttribute('one');
echo "The second parameter is " . $request->getAttribute('two');
});
我有一个同事安装了这个,所以不知道他安装了较新的版本。