The middleware for auto load routes to Slim Framework
Using Composer (Recommended)
$ composer require iosley/slim-auto-routes
Just add your routes path to 'routes.path' in Slim config and add AutoRoutesMiddleware to slim middlerares stack.
<?php
// index.php
$app = new \Slim\Slim();
$yourRoutesPath = 'routes';
$app->config('routes.path',$yourRoutesPath);
$app->add( new \Iosley\Slim\Provider\AutoRoutesMiddleware );
$app->run();
<?php
// routes/index.php
$app = \Slim\Slim::getInstance(); // need this, just if you change the variable name
$app->get('/', function() use ($app) {
echo 'Example of auto load routes to Slim Framework.'
});
The code is available at github project under MIT licence.