Hi people,
I'm creating a rest api and I need configure a route with optional parameters on querystring.
The url should be looks like: https://192.168.1.133/base/generic/lista/ OR https://192.168.1.133/base/generic/lista?q=criteria OR https://192.168.1.133/base/generic/lista?q=some+criteria&sort=-priority OR https://192.168.1.133/base/generic/lista?q=some+criteria&sort=priority OR https://192.168.1.133/base/generic/lista?sort=-priority
I want to use a unique get route for this, is:
$app->get('/generic/lista/[I DONT KNOW WHAt PUT HERE]', function([AND HERE]) {
$controller->listar($q,$sort);
});
$app is my MicroApp instance $controller is my Controller instance
And in my controller I want to validate if $q or $sort have value. I was trying with:
$app->get('/generic/lista/?{q:[a-z]*}&{sort:-?[a-z0-9]*}', function($q=null, $sort=null) {
$controller->listar($q,$sort);
});
But I don't receive %q or $sort in controller
Any clue?
Thanks