Skip to content
This repository has been archived by the owner on Sep 19, 2022. It is now read-only.

Routes params in controller #44

Open
TristanPapillon opened this issue Jun 3, 2016 · 1 comment
Open

Routes params in controller #44

TristanPapillon opened this issue Jun 3, 2016 · 1 comment

Comments

@TristanPapillon
Copy link

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 =)

@TristanPapillon
Copy link
Author

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant