Php Slim 框架 rooter 不工作
Php Slim framework rooter is not working
我不知道为什么我的 slim 应用程序表现得很奇怪,所有 url 都被视为索引“/”,示例:
我有那 3 个 urls :
$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/superuser 或任何其他事件 url localhost/ANYTHING ;我总是使用 HTTP STATUS 200
获取索引
请帮忙
您的回调应该 return 对象实现 Psr\Http\Message\ResponseInterface
,而它们 return 字符串。
因此而不是
$app->get('/', function ($request, $response){return "index";});
你应该
$app->get('/', function ($request, $response) {
return $response->write('index');
});
我也建议显示错误,至少对于开发版本。这是 link, that describes how to do that.
谢谢大家的建议,但我发现问题是由于我对 运行 内置 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 是什么,我会很高兴 :)
我不知道为什么我的 slim 应用程序表现得很奇怪,所有 url 都被视为索引“/”,示例:
我有那 3 个 urls :
$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/superuser 或任何其他事件 url localhost/ANYTHING ;我总是使用 HTTP STATUS 200
获取索引请帮忙
您的回调应该 return 对象实现 Psr\Http\Message\ResponseInterface
,而它们 return 字符串。
因此而不是
$app->get('/', function ($request, $response){return "index";});
你应该
$app->get('/', function ($request, $response) {
return $response->write('index');
});
我也建议显示错误,至少对于开发版本。这是 link, that describes how to do that.
谢谢大家的建议,但我发现问题是由于我对 运行 内置 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 是什么,我会很高兴 :)