Reputation: 10974
I'm trying to get request parameter names and values dynamically, but the array is always empty. This is the get route:
$app->get('/get/profile/:id_user', function ($id_user) use ($app) {
print_r($app->request()->params());
});
And this is how im calling it from the browser:
http://localhost/get/profile/9492
This should return an array with id_user => 9492
but it comes empty.
Any ideas why?
Upvotes: 3
Views: 16379
Reputation: 11
Also is a configuration problem。
try
try_files $uri $uri/ /index.php?$query_string;
Upvotes: 0
Reputation: 43
You can use following:
$app->get("/test.:format/:name",function() use ($app){
$router = $app->router();
print_r($router->getCurrentRoute()->getParams());
});
Upvotes: 3
Reputation: 38645
Notice: Please read update notes before trying out this code. The update note is my first comment in this answer.
Couldn't get to test it but please try the following:
$app->get('/get/profile/:id_user', function ($id_user) use ($app) {
$req = $app->request();
print_r($req->params());
});
Reference documentation: http://docs.slimframework.com/#Request-Method
Update: Okay after some digging figured the following, the params()
method requires a parameter. If called without a parameter a Notice is raised. Checking the source revealed that this function called without a parameter returns null. See Http/Request.php
line 199. Also for some reason currying does not seem to work either to retrieve parameters so you have to use the function parameter $id_user
which has the expected value.
Upvotes: 4