Being a micro-frame, Slim does not apply any specific method. You can either find a ready-to-use structure ( Slim Skeleton Application ), or write your own; unlike other frameworks, Slim does not try to protect you from PHP.
Route definitions can be as simple as an array of strings:
<?php // routes.php return [ '/' => ['Foo\\Home', 'index'], '/about' => ['Foo\\Home', 'about'], '/contact' => ['Foo\\Contact', 'form' ], ];
... which you load and process at the entry point index.php :
$routes = require('/path/to/routes.php'); foreach ($routes as list($path, $handler)) { $app->get($route, $handler); }
And you can use existing Composer to automatically load your classes by adding the appropriate directories to composer.json :
{ "require": { "slim/slim": "^3.3", "monolog/monolog": "^1.19" }, "autoload": { "psr-4": {"Foo\\": "./Foo/"} } }
Here it can be as complicated as possible: define routes in the YAML file, automatically load certain classes, etc.
(Code samples are shown for illustration and may even be invalid.)
source share