I've lately been developing my own MVC content management system using PHP and, at least in my mind, am a little stuck with the system design. I believe this would apply to building a content management system with an existing MVC framework as well.
This is going to be a little difficult to explain, so sorry in advance for the lengthy dilemma.
A little intro to the system:
Currently my routes look a little like this (stored as JSON):
The routes are the keys, the default controllers are the values. If there isn't a default controller the router falls through to the next rule. I've done this to separate the front end of the site from the admin panel.
The controllers are all in one directory for the time being, although this is destined to change. They either return a template that's been populated with data from their respective model or simply modify the request they were instantiated with.
My problem is with deciding how to implement separate controllers that concern the same model for the front end and the back end in a modular way.
For example, I have a page in the admin panel that allows an administrator to enter some private information that's intended only to be accessible on the front end with a username and password. Imagine this is handled by an
InfoController in the back end, for editing the private information, matched by the route
What if I wanted to create a route for the front end, for accessing the private information, with the same name as in the admin panel (
The problem makes more sense in context with the solutions I've considered, I think.
Solutions I've considered:
- My first thought was to append all admin-related controllers with
Infomodel would be in their own directory structure (something like
- With the desire for modularity in mind, I thought about matching routes a bit like
/:module/:controller/:action, but this would then imply that the admin panel is itself a module, which would need access to all the modules the front end can use. Would that make sense?
- The design I've thought about the most is to have the admin and front end as two distinguished, core concepts of the framework. They would share modules that contain controllers and views for both.
Ultimately I'm looking for input on the best approach here, any alternatives, and whether I'm totally over-thinking this.
It feels a bit like I've driven myself crazy with the pursuit of my ideal system design that keeps with the MVC pattern (is it even the right thing for a system like this?). Thanks for reading, I hope it made sense.