What I learned from creating my own CMS

First of all you should know my reasoning behind building this from scratch. I wasn't trying to reinvent the wheel, I was merely trying to figure out how the wheel works so I that I could make the car run more smoothly.

The Structure

Having worked with Drupal, Wordpress, and various other CMSs I knew the importance of good file structure. After looking at various sites I decided on a common structure to start with. CMS Site Structure

Each time a user clicks a link it goes through a process to find and display the correct page.

  1. The system includes all of the application classes, this includes the controller, registry, router, and template)
  2. The DB is then instantiated using the Singleton design pattern
  3. The next step is to instantiate the registry object. This stores information about the URL, page id, user id, user permissions, etc... it is basically the equivalent of a config file. Site wide variables are stored here so they can be passed to the controller files
  4. The router object is next to be instantiated. The router takes the URI and breaks it into parts. From these parts it knows to call a certain controller and action. For instance www.levijackson.net/page/checkpage/1 would call the page controller, the action (or method) checkpage, and it would pass in the id of 1 to the action to process.
  5. The next step is to instantiate the template object. The registry object we called earlier holds all of the template variables to use in building the dynamic pages.
  6. The last thing that occurs (or the first from the user perspective) is that the index controller is called which takes ALL of the info we generate in the above steps and puts it all together into one neat and tidy page.

Snippet

Upsides to working in OOP PHP

After working with Object Oriented PHP on a large project for the first time I found that I enjoyed it much more than I thought. Some of the things I enjoyed while working on the OOP CMS were:

  • How easy it was to debug when most processes pass through one file.
  • How easy it was to write an action and deploy it site wide.
  • How easy it is to change the design without changing the architecture of the site.
  • How easy it was to keep with the DRY (Don't Repeat Yourself) principle of coding.

Conclusion

It took entirely too long to bring this CMS from development to production. Total time would put this project at around 60 hours of research, coding, design, and using a punching bag to alleviate stress. From doing this it has definitely opened my eyes to how important it is to be DRY when coding.

Posted: August, 21 2010