views:

4676

answers:

6
A: 

I have done this every which way for various projects. From coding everything for an application in one great big PHP script (OK it started as a small PHP script which just grew). To using the latest greatest Spring/Freemarker framework where my 5O lines of java code were lost in a sea of XML and template coding.

You can do MVC without a framework, and, in php this is probably the simplest way. If all your navigation code is in a single script with only navigation logic then you are doing MVC!

For anything other than a QDP (Quick Dirty Page) I would recommend using some sort of MVC. Just imagine what you would need to do if the business said "can I have a French language version" or "great program but I want to store the data in xxxxx database".

James Anderson
A: 

Its often hard to clearly separate your view logic with your business logic. If you read up abit on JSF & JSP examples you can see clear examples of MVC in use. Completely seperating the view from the business logic.

If your looking for good information about MVC I can suggest http://en.wikipedia.org/wiki/Model-view-controller

This is an important topic and I really like the idea of sepperating the different logics. It helps the programmer and everyone else working on the project.

ChrisAD
+1  A: 

Assuming you mean MVC for the web you'd be hard pressed to find anything more concise than the following 60 lines of code:

http://code.google.com/p/barebonesmvc-php/

In particular note the sendResponse "template method", which in turn is essentially comprised of the following 2 method calls:

applyRequestToModel

applyModelToView

George Jempty
+3  A: 

IMO, the best examples are with code and/or starter kits.

Rob Conery has a great number of posts that explain how to to create an MVC site with ASP.NET MVC. Each one of these has a video tutorial which runs through the blog post disucssion.

The official ASP.NET MVC site also has some video posts, starter kits (here, here and here) and extra sauce to help.

IMO, MVC is the way to go for Web Sites. Without spewing all the jargon and marketting speak, it really breaks down your code into nice, separate and defined sections. Each of these sections can also be tested .. which really helps protect the development process because you have peace of mind knowing that touching one part of the system doesn't break another (because the tests all pass after your latest change).

Other blogs which u should check out:

Pure.Krome
A: 

@George J - I just went over the Bare Bones PHP example, and I feel it has a lot of problems for one just starting to look into MVC (aka, someone like myself)

First, for someone wanting to just understand the basics, you can get rid of the interfaces and abstract base classes. Although a real MVC implementation should definitely use them, they just clutter up your example. 60 lines would become more like 30.

Second, the model is never actually constructed! Instead, it's implicitly instantiated in an abstract base class. I would think that this is an important step. The seemingly relevant setModel() function is in fact never called.

Third,the "model transfer object" is barely mentioned anywhere else on the web. This is a distraction and only creates more confusion for the developer.

Fourth, it would be nice to mention the point at which user interaction is processed. It's something the newbie would like to know.

anon