I don't know why my slim app is acting strange, all urls are considered as index "/", Example:
i have those 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";});
if i go to localhost or localhost/user or localhost/superuser or event any other url localhost/ANYTHING ; I always get index with HTTP STATUS 200
Help Please
Your callbacks should return objects implementing Psr\\Http\\Message\\ResponseInterface
, while they return strings.
Thus instead of
$app->get('/', function ($request, $response){return "index";});
You should have
$app->get('/', function ($request, $response) {
return $response->write('index');
});
I also suggest to display errors, at least for development version. Here is the 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我会赞成:)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.