Bridge for using Slim with Craft
This is probably only of interest to me, but you're welcome to use this project if you come across it and like it.
I really like working in Slim, with FastRoute, and PSR standard interfaces. To that end, I've created this extremely simple Craft Plugin that let's me do the front-end of Craft sites in Slim and mostly ignore that Craft is there in the background.
- In your craft project, run
composer require buzzingpixel/craft-slim-bridge
- Then run
php craft plugin/install slim-bridge
- Create a config file in your
slim-bridge.php. See Config section below for configuration.
- Add the following catch-all route as the last route in your craft
'<path:.*>' => 'slim-bridge/route-handler/index',
- For Category or Entry routing through Slim, use the following format in the site settings
templatefield to route to custom class's
- If you want to add route middleware or manipulate the route in other ways, implement
return [ '/some/craft/route' => 'some-template-or-action', '/another/craft/route' => 'another-template-or-action', '<path:.*>' => 'slim-bridge/route-handler/index', ];
Two keys are available in the config file (See example):
Slim requires an implementation of
\Psr\Container\ContainerInterface and I've left this to project owners to provide. I, personally like PHP-DI.
This is optional, but if you don't use it, then you won't have set any routes or middlewares and it will be useless to you. Once the app has been created, this callback will be run and the argument recieved will be the Slim App instance which you can use to set routes and middleware.