gazareth
gazareth

Reputation: 1154

Route parameters with Slim 3 & built-in PHP server

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?

Upvotes: 7

Views: 3349

Answers (1)

Federkun
Federkun

Reputation: 36934

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.

Upvotes: 8

Related Questions