riverside / php-express

:horse: PHP micro-framework inspired by Express.js
https://riverside.github.io/php-express/
MIT License
28 stars 11 forks source link

[Question] How to pass Custom Parameters inside URL #3

Closed cstayyab closed 3 years ago

cstayyab commented 4 years ago

Hi!

I have read code and documentation provided but I couldn't find a way to pass parameters like we do in express.js. Yeah I did find a way to pass "hash" and numeric "id" but not a custom parameter.

$app.get('/user/:username', function ($req, $res) {
    $res->send($req->params['username']);
}

Is there a way to do that in php-express?

Meleeman01 commented 3 years ago

https://github.com/riverside/php-express/blob/master/src/Request.php#L14 it should be possible to pass query parameters, i didn't write this and i just stumbled upon this gem. in theory you could write the functionality in here, definetely doable. although i'm not exactly sure what you mean by parameters.

riverside commented 3 years ago

I just commit a fix that address this issue. Application and Router now have a new method 'param'. You can use it like this: https://riverside.github.io/php-express/api.html#app-param https://riverside.github.io/php-express/api.html#router-param