I am trying to offer an an endpoint to the API I am building that accepts routing parameters.Something like:
example.com/api/endpoint.php/param
to allow param
as string to act as the parameter for the call to the endpoint. So all I really need is the ability to know what the string after the slash is.
I understand to do this I need something to handle routing for me, and Klein php seems to be a popular light weight routing ... framework.
I am sure this is very simple but the documentation isn't really clear on it to me - here is what I am trying
$klein = new \Klein\Klein();
$results = $klein->respond(function () {
return 'Everything';
});
print_r($results );
But this gives
Klein\Route Object
(
[callback:protected
] => Closure Object
(
)
[path:protected
] => *
[method:protected
] =>
[count_match:protected
] =>
[name:protected
] =>
Something obvious I'm doing wrong here? Thanks!
EDIT: per @ArSeN comment I have updated to :
$klein = new \Klein\Klein();
$klein->respond(function () {
return 'All the things';
});
$klein->dispatch();
But, nothing happens, how can I actually access and use the string that comes after / in the same way I would a get param like $_GET['param']
?
My Answer:
>param('param', function($param) {
echo "The parameter is: " . $param;
});
$klein->dispatch();
Rate this post
4 of 5 based on 7547 votesComments