handsome
handsome

Reputation: 2392

route group slim framework

I want to create a ¨dynamic¨ route group in Slim framework but I´m getting

Warning: Missing argument 1 for {closure}() i

this is my code:

\Slim\Slim::registerAutoloader();

$app = new \Slim\Slim();

$app->group('/:segment1/:segment2', function ($segment1, $segment2) use ($app) {

    $app->map('/', function () use ($app) {

    })->via('GET', 'POST');

    $app->map('/:id', function ($id) use ($app) {

    })->via('GET', 'PUT', 'DELETE');

});

$app->run();

If i change:

$app->group('/:segment1/:segment2', function ($segment1, $segment2) use ($app)

to:

$app->group('/segment1/segment2', function () use ($app)

it starts working but I need those segments to be dynamic. how can I do that?

Upvotes: 1

Views: 1982

Answers (1)

danopz
danopz

Reputation: 3408

You have to add group parameters to their child routes function:

$app->group('/:segment1/:segment2', function () use ($app) {

    $app->map('/', function ($segment1, $segment2) use ($app) {
        // something
    })->via('GET', 'POST');

    $app->map('/:id', function ($segment1, $segment2, $id) use ($app) {
        // something
    })->via('GET', 'PUT', 'DELETE');
});

Also look at this issue.

Upvotes: 2

Related Questions