【问题标题】:No such file or directory PHP SLim没有这样的文件或目录 PHP SLim
【发布时间】: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.emailreq.params.password 来获取参数,但我不知道如何在 PHP Slim 中使用它。感谢您的帮助。

【问题讨论】:

    标签: php slim slim-3


    【解决方案1】:

    不建议在 URL 中使用 @ 符号作为伪“参数”,否则可能会导致路由问题。为了使其更好地工作,您可以改用经典查询字符串。

    GET example.com/user?email=test@gmail.com
    

    【讨论】:

      猜你喜欢
      • 2013-01-16
      • 2018-02-25
      • 1970-01-01
      • 1970-01-01
      • 2017-09-26
      • 2014-02-04
      • 2018-08-31
      • 2023-04-07
      • 1970-01-01
      相关资源
      最近更新 更多