The Slim Framework support forum has moved to This Tender forum is no longer maintained or monitored.

Slim PHP as a CMS Base

steve's Avatar


02 Jul, 2015 07:42 AM


I am about to start building a bespoke CMS at work, as they do not want to use one that is pre-built. I want to use SLim but am trying to figure out the best way to do routes? Does anybody have any advise for this?

What I was thinking was that each Route would have a page type, which correlates to a Controller for that type - however it is early in the morning and lack of sleep is not helping my brain function!

If anyone has tried this before, or have any advise etc etc I would be grateful!

  1. 1 Posted by Kapoler on 03 Jul, 2015 08:13 AM

    Kapoler's Avatar

    You can simply do

    $app->get('/yourpage', '\controller\yourpageclass:yourpagefunction');

  2. 2 Posted by steve on 03 Jul, 2015 08:30 AM

    steve's Avatar

    Sorry, what I mean was it would all be dynamic.

    So for example I would add a page to the database which would save the route "page-name", the page type "page-type" and then I would listen for the "page-name" in the router then when called send it to the controller which looks after that "page-type".

  3. 3 Posted by Tom on 22 Sep, 2015 12:19 PM

    Tom's Avatar

    This is exactly what I need to achieve. Currently don't have a solution... Steve did you ever work this out?

  4. 4 Posted by Steelcat on 25 Sep, 2015 05:34 PM

    Steelcat's Avatar

    You can use the dynamic formation of controller name:

    In my own cms this code works fine, but for Symfony:

      $extClass = 'Zorca\Ext\\' . ucfirst($matchResult['_route']) . 'Ext';
      $extController = new $extClass;
      $response = $extController->run($request, $matchResult['extAction']);

    For Slim may be:
      $extClass = 'Zorca\Ext\\' . ucfirst($matchResult['_route']) . 'Ext';
      $app->get('/:extname', $extClass);

  5. 5 Posted by John on 27 Sep, 2015 03:59 AM

    John's Avatar

    Would something like this work?

    $app->get("/page/:pagename/:pagetype", ... );

    (I'm a noob.)

  6. 6 Posted by steve on 27 Sep, 2015 10:46 AM

    steve's Avatar

    Something along those lines should work, that way you could save the routes in the DB and tag it as "page" or "blog" or similar.

    You could possibly drop the "page" part of the URL as the main routes will be pages anyway, and then each specific part like blog etc would route of that URL so controllers can be set easier.

    It would just mean getting and matching URLs as soon as the application loads so you don't miss URLs.

    The GET, POST, PUT, DELETE could be a little trickier to work into it but I guess not impossible?

  7. 7 Posted by Josh on 03 Oct, 2015 12:49 AM

    Josh's Avatar

    I'm also looking at using slim for the base of a CMS. I have written a CMS in Yii1.1 before and "hijacked" the 404 route to render the pages from the database.

    It's a bit roll-your-own but realistically the CMS frontend does not need to use routing specific for every page, in fact it's more intelligent not to.

    The backend of the CMS should use routing for CRUD of pages, posts, products etc and the routing controller is perfect for that.

  8. 8 Posted by Luca on 15 Oct, 2015 09:27 AM

    Luca's Avatar

    I'm not sure whether I have understood the question but you could use a db table for it like this:

    name | path | type | is_child_of | controller | middleware | active

    Contains the name of the route, the path, its type (Post, Get, etc), whether its the child of another route (the PHP evaluation would have to create a group for it), the controller and the middlewares name (PHP would have to read out the middleware somewhere and add it to the route).

    Query this information from the db, evaluate it and thats it.

    PS: Maybe you remember me from Reddit dude! :)

  9. 9 Posted by on 06 Jan, 2016 10:08 PM's Avatar

    Since Slim->get($pattern, $callable) has two string parameter so I think it might be possible to dynamically build the string before pass to get()

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac