Ananda Pramono
Ananda Pramono

Reputation: 1009

No such file or directory PHP SLim

I'm new in Slim framework and I have a problem about routing. Tried to follow the guide,but it still give me no such file or directory error. THis is my route

$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);
});

This is how I call my route localhost:8080/user/[email protected]

And Have some more question, can we use two parameter and use it in query? This is the example 'user/{email}/{password}' And call the url localhost:8080/user/[email protected]/pass. Usually I use NodeJs and use req.params.email and req.params.password to get the params, but i dont have any idea how to use it in PHP Slim. Thank you for your help.

Upvotes: 0

Views: 253

Answers (1)

odan
odan

Reputation: 4952

Using the @ sign in a URL as a pseudo "parameter" is not recommended and can cause routing issues. To make it work better, you can use a classic query string instead.

GET example.com/[email protected]

Upvotes: 1

Related Questions