代码之家  ›  专栏  ›  技术社区  ›  FrenchTechLead

Php Slim framework rooter不工作

  •  0
  • FrenchTechLead  · 技术社区  · 9 年前

    我不知道为什么我的slim应用程序表现奇怪,所有URL都被视为索引“/”,例如:

    我有这3个网址:

    $app->get('/', function ($request, $response){return "index";});
    $app->get('/user', function ($request, $response){return "user";});
    $app->get('/superuser', function ($request, $response){return "superuser";});
    

    如果我转到localhost或localhost/user或localhost/超级用户或事件,任何其他url localhost/任何内容;我总是得到HTTP状态为200的索引

    请帮帮我

    2 回复  |  直到 9 年前
        1
  •  3
  •   Georgy Ivanov    9 年前

    回调应该返回实现 Psr\Http\Message\ResponseInterface ,而它们返回字符串。

    因此,代替

    $app->get('/', function ($request, $response){return "index";});
    

    你应该

    $app->get('/', function ($request, $response) {
        return $response->write('index');
    });
    

    我还建议显示错误,至少对于开发版本。这是 link, that describes how to do that .

        2
  •  0
  •   FrenchTechLead    9 年前

    谢谢大家的建议,但我发现问题是由于我运行内置php服务器的错误命令造成的 php -S 0.0.0.0:8080 public/index.php 而不是这个: php -S 0.0.0.0:8080 -t public public/index.php 如果有人能向我解释-t public做什么,我会回答:)