PHP code example of mangopeaches / slim-route-groups

1. Go to this page and download the library: Download mangopeaches/slim-route-groups library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mangopeaches / slim-route-groups example snippets


$app->group('/users', function($app) {
    $app->get('', 'Path\To\Users:getAll');
    $app->post('', 'Path\To\Users:create');
});

$app->group('/books', function($app) {
    $app->get('', 'Path\To\Books:getAll');
    $app->post('', 'Path\To\Books:create');
});


use SlimRouteGroups\Routes;

class UsersRoutes extends Routes
{
    /**
     * Define user routes.
     */
    public function __invoke()
    {
        $self = $this;
        $this->group('/users', function($app) use ($self) {
            $self->get('', 'Path\To\Users:getAll');
            $self->post('', 'Path\To\Users:create');
        });
    }
}



use SlimRouteGroups\Routes;

class BooksRoutes extends Routes
{
    /**
     * Define books routes.
     */
    public function __invoke()
    {
        $self = $this;
        $this->group('/books', function($app) use ($self) {
            $self->get('', 'Path\To\Books:getAll');
            $self->post('', 'Path\To\Books:create');
        });
    }
}