7

I'm having problems getting routes with parameters to work in Slim 3 RC.

$app->get('/hello/:name', function($req, $res, $args) {
    echo "Hello {$name}";
});

Visiting /hello/joe results in 404.

Other routes work fine, e.g.:

$app->get('/', HomeAction::class . ":dispatch");

$app->get('/services', ServicesAction::class . ":dispatch");

I am using the built-in PHP server while I am developing. I do not have any .htaccess file. I have tried the suggested route.php suggestion and the accepted answer from this question but it does not work. Any suggestions please?

Community
  • 1
  • 1
gazareth
  • 1,135
  • 10
  • 26

1 Answers1

8

From Slim 3 you need to change :name in {name}.

$app->get('/hello/{name}', function ($request, $response, $args) {
    return $response->write("Hello " . $args['name']);
});

You can find the documentation here.

Federkun
  • 36,084
  • 8
  • 78
  • 90
  • 1
    Thank you. Amazing how many times I looked at the version3-specific documentation while debugging this one but somehow missed the syntax change :-) – gazareth Oct 04 '15 at 19:22