So the docs say this
Route groups
To help organize routes into logical groups, the \Slim\App also provides a group() method. Each group’s route pattern is prepended to the routes or groups contained within it, and any placeholder arguments in the group pattern are ultimately made available to the nested routes:
$app = new \Slim\App();
$app->group(‘/users/{id:[0-9]+}’, function () {
$this->map([‘GET’, ‘DELETE’, ‘PATCH’, ‘PUT’], ‘’, function ($request, $response, $args) {
// Find, delete, patch or replace user identified by $args[‘id’]
})->setName(‘user’);
$this->get(‘/reset-password’, function ($request, $response, $args) {
// Route for /users/{id:[0-9]+}/reset-password
// Reset the password for user identified by $args[‘id’]
})->setName(‘user-password-reset’);
});
Note inside the group closure, $this is used instead of $app. Slim binds the closure to the application instance for you, just like it is the case with route callback binds with container instance.
inside group closure, $this is bound to the instance of Slim\App
inside route closure, $this is bound to the instance of Slim\Container
However what I am finding more and more of, is that the documentation which is meant to help us NOOBS makes us confussed, why can’t the developers take the time to clearly show examples of just how the above works.
This is how the above left me.
-
Where do I link the map too? does the [‘GET’, ‘DELETE’, ‘PATCH’, ‘PUT’] have the same code? or do they do different things?
- What I mean by this if I want to delete say the users account is that code inside the map code
’
$this->map([‘GET’, ‘DELETE’, ‘PATCH’, ‘PUT’], ‘’, function ($request, $response, $args) {
// Find, delete, patch or replace user identified by $args[‘id’]
DO I PUT THE CODE HERE AND HOW DO I SAY THIS CODE FOR DELETE THIS CODE FOR GET ETC.
})->setName(‘user’); - What I mean by this if I want to delete say the users account is that code inside the map code