RSS

Basic MVC Web Site Developed In PHP

0 Comments | This entry was posted on Dec 13 2010

Last week a front-end developer friend emailed me asking if I had a simple MVC type website template that he could use to build basic static websites, similar to one that I developed for a job that we worked on together at an agency. The answer was not yet but I’ll make one.

Sometimes I work on small sites myself but always tend to build basic sites from scratch each time for such cases that don’t require an established PHP framework. However this time I thought I would use this as an excuse to build something that I can re-use and share with others.

I gave myself an hour to build something that would be easy for others to understand and use but also be clean and extensible. There is no functionality to allow user input, a database abstraction layer (or any database functionality) or other things commonly seen in frameworks. About the only dynamic code that non PHP developers could take advantage of is the active state for the navigation menu.

The would be MVC at its most basic:

Model:

I guess as there is no database in a static site so there is no reason for a real model to be included at this time.

View:

The views can be found and added in the /views folder. The views are really just the content for a particular page and does not include the page layout. The layout (or templates as most CMSs call them) exist in the /templates directory. The idea is to separate page content from page layout. The layout file will load the content file via an include.

Controller:

The controller is very basic and currently is just used to load the layout which in turn loads the content. This main controller file is where most functionality should be added.

Conclusion:

The idea is very basic but I hope people can make use of it. I can see that new features will be added as people make requests. In return I wouldn’t mind if someone changed the default style sheet to make it more appealing and send it back to me.

The website template can be downloaded from GitHub at: https://github.com/doublehops/Basic-MVC-site

The website template ended up taking two hours to complete but my friend has been using it and is happy with it.