【问题标题】:Slim PHP not seeing url params Windows Server with IISSlim PHP 看不到 url 参数 Windows Server with IIS
【发布时间】:2016-06-03 00:05:08
【问题描述】:

我在使用 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 所在的位置。

【问题讨论】:

  • 你怎么称呼路线?
  • 我在做www.example.com/api/books/a/b 无论如何,我已经找到了我的问题。这是苗条的版本,如下面我的回答中所述。

标签: php iis slim


【解决方案1】:

显然 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');
});

我让一个同事安装了这个,所以不知道他安装了较新的版本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-11
    • 1970-01-01
    相关资源
    最近更新 更多