slimcontroller
slimcontroller copied to clipboard
Routes params in controller
Hi and thanks for your contribution,
I have a problem to get the values of routes parameters.
In my routes, I want to get the "id" param in the controller :
$app->addRoutes(array(
'/' => 'front\Home:index',
'/admin/categories' => array('get' => 'back\Category:index', 'post' => 'back\Category:save'),
'/admin/categories/new' => 'back\Category:add',
'/admin/category/:id/edit' => 'back\Category:edit'
));
In my controller
class Category extends \app\controllers\Back
{
...
public function edit()
{
$args = func_get_args();
$params = $this->request()->params();
var_dump($args, $params);
exit();
}
}
$args var_dump (if the id is 6 : http://localhost:3000/admin/category/6/edit) :
array (size=1)
0 => string '6' (length=1)
$params var_dump :
array (size=0)
empty
Is there a function to map get parameters with routes parameters ? I don't find method or any example. Thanks for help, i'm not habituate to use Slim =)
I found this.
$this->app->router()->getCurrentRoute()->getParams();
The route param is associate to his value :
array (size=1)
'id' => string '6' (length=1)
It's one of the first time I use Slim & SlimController, I'm suprised that I'm alone to have this issue. There is a better solution that I don't know?