【发布时间】:2021-09-09 20:42:53
【问题描述】:
我是 Slim 框架的新手,我对路由有疑问。尝试按照指南进行操作,但它仍然给我no such file or directory 错误。这是我的路线
$app->get('/user/{email}', function (Request $request, Response $response, array $args){
$email = $args["email"];
$sql = "SELECT * FROM user WHERE email=:email";
$stmt = $this->db->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll();
return $response->withJson(["status" => "success", "data" => $result], 200);
});
这就是我如何称呼我的路线localhost:8080/user/test@gmail.com
还有一些问题,我们可以使用两个参数并在查询中使用它吗?这是示例'user/{email}/{password}' 并调用url localhost:8080/user/test@gmail.com/pass。通常我使用 NodeJs 并使用 req.params.email 和 req.params.password 来获取参数,但我不知道如何在 PHP Slim 中使用它。感谢您的帮助。
【问题讨论】: