DEV Community

Discussion on: My PHP Toolkit to Build a (quite) Frameworkless App

Collapse
 
biros profile image
Boris Jamot ✊ /

I'm used to build small to medium apps with something like 50kLoC.
I have no specific strategy so I usually end up with big routes files.
As you may know, Slim routes take a closure to handle the request and give the response:

$app = new \Slim\App();
$app->any('/books/[{id}]', function ($request, $response, $args) {
    // do the stuff here
});

Instead of having a big routes file, we have the possibility to define a controller class and to pass it to the \Slim\App:

$app = new \Slim\App();
$app->any('/books', BookController::class);

I never tried that but it's well described in the official doc.

Collapse
 
hsemix profile image
Hamid Semix

You could install a DI container and do something like this

 $app->get('/books', 'BookController@getBooks');