This is part 2 of the programming your own php framework – view part 1. The below article was authored by Terry Smith. Terry is an aspiring entrepreneur and PHP code ninja working for b5media. He spends his “weekends” and “free time” working on all sorts of crazy ideas and one day wants to rule the world (or a small part of it)!
To get things started, you should be familiar with the Model-View-Controller paradigm. The basics components are models (classes/objects/etc.) that represent items in your application (users, database records, etc.), controllers which do the processing for a page or module and views, which contain the HTML/CSS for your output. You can read more about it here.
Step 1: Directory Structure
As noted in the last part, I have chosen to structure my URLs in the format
In this case, the controller indeed represents the controller in the MVC paradigm. I will take a moment to explain the directory structure I’ve used; again, note that you can use almost any structure for your own applications.
/config – Basic configuration files (database settings, etc.)
/controllers – Controllers are all in this directory.
/lib – Default library files included with every new site I deploy (database class, URL rewriting, templating and other base classes)
/models – Custom models for each application (users, sessions, etc.)
/views – View files (PHP files), that contain the HTML
/web – The actual web directory we point our web server to.
There are two things of note here. First, our images, CSS, etc. go into our
/web directory, since the web server can’t read anything above the
Second, and most important, all of these files should be outside/above the directory you actually point your web server to serve files from.