CMS for Slim (PHP): Content Without Bloating a Microframework
Keep the microframework lean, handle content separately
Slim is a PHP microframework — routing, middleware, PSR-7 requests, and little else. You reach for it when you want a lightweight API or a small app without the weight of a full framework. Like all microframeworks, it gives you nothing for content: no CMS, no admin, no content model. For a Slim app that needs a blog or marketing pages editable by non-developers, the clean answer is a headless CMS behind an API. This post covers how to wire one to Slim and why a self-hosted content layer fits a lean PHP stack.
Content in a Slim app
Slim is deliberately minimal, so building a full CMS inside it defeats the purpose — you'd be reconstructing a framework's worth of features (admin, media, SEO, publishing) on top of a microframework. Two sensible paths:
Headless CMS: content lives in a dedicated service with its own admin and API. Slim fetches it and renders it (or your front end does). Keeps Slim lean; non-developers get a real editor.
Static + API: if your Slim app serves mostly static content, prerender pages from CMS data at build/deploy time and let Slim serve the rest.
For anything a writer edits, headless is the fit — you don't want a microframework carrying a content backend.
Fetching CMS content in Slim
Slim uses PSR-18 HTTP clients cleanly. With Guzzle:
$app->get('/blog', function ($request, $response) {
$client = new GuzzleHttp\Client();
$res = $client->get('https://cms.yoursite.com/api/v1/posts?per_page=20');
$posts = json_decode((string) $res->getBody(), true)['data'];
// render with your template engine (Twig, Plates, etc.)
return $this->get('view')->render($response, 'blog/index.html', ['posts' => $posts]);
});
$app->get('/blog/{slug}', function ($request, $response, $args) {
$client = new GuzzleHttp\Client(['http_errors' => false]);
$res = $client->get("https://cms.yoursite.com/api/v1/posts/{$args['slug']}");
if ($res->getStatusCode() === 404) {
return $response->withStatus(404);
}
$post = json_decode((string) $res->getBody(), true)['data'];
return $this->get('view')->render($response, 'blog/detail.html', ['post' => $post]);
});
Cache responses (a simple PSR-16 cache) so you're not calling the API every request. The CMS returns a { success, message, data } envelope, and drafts return 404.
Why a PHP-native headless CMS fits Slim
Slim developers value lightness and control, running their own PHP infrastructure. A SaaS CMS with metered API calls and vendor-owned data works against that. A self-hosted, PHP-native CMS keeps everything in your world.
UnfoldCMS is one option. It's a self-hosted CMS built on Laravel (PHP 8.3) with a REST API at /api/v1/*. Being PHP, it shares your hosting and ops — even if your Slim app is tiny, the CMS runs on the same kind of LAMP box. You consume it headless; Slim stays a microframework.
Key fits:
- Same hosting world — PHP on LAMP; no new runtime for a Slim shop.
- REST + JSON — clean for a PSR-18 client and any template engine. No GraphQL client.
- No SDK — standard HTTP via Guzzle or any PSR-18 client.
- Self-hosted, pay once — your server, your data.
Cache busting with webhooks
Cache CMS responses and clear them on change. UnfoldCMS fires outgoing, HMAC-signed webhooks on publish/update/delete. Add a Slim route that verifies the signature and clears the cache — an editor publishes, the stale cache clears immediately.
Tradeoffs to weigh
- A separate app. UnfoldCMS is a full Laravel application, not a Slim-sized component. It's heavier than Slim itself — the point is that Slim stays lean while the CMS handles content separately.
- A network hop. Content comes from an API call; caching hides the latency.
- No revision history. UnfoldCMS doesn't keep past versions of posts.
- REST only, no GraphQL.
- Preview needs wiring. Drafts 404 on the public API.
FAQ
Does Slim have a CMS? No. Slim is a microframework with no CMS, admin, or content model. Connect a headless CMS via its API rather than building a content backend inside Slim.
Can a lightweight Slim app use a full CMS? Yes — headless. The CMS runs as a separate service; Slim just fetches its API and stays lightweight. Your app doesn't inherit the CMS's size.
Why a PHP-based CMS for a PHP app? It shares your hosting and ops. A PHP-native CMS like UnfoldCMS runs on the same LAMP infrastructure and deploys with composer — no second runtime to operate.
How do I keep it fast? Cache CMS responses with a PSR-16 cache and bust the cache via a webhook when the CMS fires a publish event.
Bottom line
Slim stays a microframework; a self-hosted, PHP-native headless CMS handles content separately over a REST API. Fetch with a PSR-18 client, cache it, and bust the cache with a webhook on publish. The CMS is a separate (heavier) app, but it shares your PHP hosting and ops, and Slim keeps its lean footprint. For a Slim app that needs a real editor without bloating, that's the fit.
See the demo or read about PHP headless CMS.
Related: CMS for PHP developers · PHP headless CMS · CMS for Symfony
Free & Open Source
Own your CMS. No subscriptions.
Unfold CMS is free to download and self-host. Built on Laravel + React, full source code included.
Share this post: