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

Routes params in controller #44

@TristanPapillon

Description

@TristanPapillon

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions