CMS Routing in MVC

Instead of simply using explode() to separate the segments of URL, you could use a set of regular expression pattern.

For example, this following patter would try to match at firsts action, and, if action exists them check if there is controller set before it:

'/(:?(:?\/(?P<controller>[^\/\.,;?\n]+))?\/(?P<action>[^\/\.,;?\n]+))?/'

Most of PHP frameworks use different ways to generate such patterns, with simplified notations. This way you can set which parts for each pattern are mandatory and which optional. And it is also possible to provide fallback values for the optional parts.

That said …

Before starting to make something so complicated as cms with framework, you might invest some additional time in researching OOP. I would recommend to at least watch lectures from Miško Hevery and Robert C. Martin. Just because you think, that you know how to write a class, does not mean, that you understands object oriented programming.

Update

I have listed few materials in this answer. You might find them useful,

Additionally here are two more lectures, that were not in answer above:

Leave a Comment