From GeeklogWiki
Jump to: navigation, search


If you don't know what it is, you better ask somebody. Separating the user interface from business logic from data access is a framework essential and is key to making your application easier to maintain. Most MVC implementations break code into atomic units of work that encourage reuse and maintainability. Geeklog 2 uses MVCnPHP to accomplish this.


MVCnPHP, Model-View-Controller iN PHP, is a simplified MVC implementation based very loosely off of Phrame and Struts with all the garbage taken out. If you are Java programmer and a Struts fan, don't take too much offense as I believe it is a good tool but it aims at doing more than a simple MVC implementation. Phrame similarly is a Struts-like MVC implementation that share many of the same problems in Struts. I wrote MVCnPHP back in 2003 because, in my opinion, there wasn't a bare bones, intuitive MVC implementation in PHP. Since it's release back in 2003 it has kept it's simplicity and has significantly improved performance. From this point on I'm going to assume you know what MVC and are eager to learn how to implement MVCnPHP in your application.

Models, Views, Controllers Defined

Models are the data structures your PHP application will use and they represent the core business components of your business. So, for example, you may very well have models that represent users, accounts and transactions. Models are ideally simple PHP classes that are made up of members and their accessors (i.e. getters/setters). Views are mechanisms used to render one or more models to a users. Views are the visual component and in most basic web development terms are represented by a single screen. A controller manages program execution between models and views and commands. What's this command thing? Commands are implementation of the command design pattern. Commands are simply used to represent actions. Thus it is quite typical in MVC implementations to have a view submit data to a command which in turn requests another view to be show all being dispatched by the controller. Is all this fuzzy? No worry, let's look at each piece of MVCnPHP in more detail.

  1. MVCnPHP Installation
  2. Using the Controller
  3. Building a View
  4. Understanding the MVCnPHP Configuration File
  5. Building a Command
  6. Using Forwards
Personal tools