The online racing simulator
OT PHP: Do you use the Model-View-Controller-Pattern?
Good Morning dear Programmers

I have heard lotsa different opinions about the above-mentioned pattern. Some people tell me it is very useful, others say it is simply overkill. I would like to hear your opinion about it, because I know there are lots of very skilled PHP programmers around here.

For Everyone that does not know what the MVC Pattern is, an explanation:

The MVC Pattern explained

The MVC Pattern is a Pattern meant to enable very flexible software design. It basically makes the whole application consist of three different object types: "Models", "Views" and "Controllers". There has to be a common interface for each of these types that every object of the specific type has to implement. Basically meaning the following:

<?php 
// Create interfaces. Normally, common methods would be defined here
// That every class has to implement
interface MyModel {}
interface 
MyView {}
interface 
MyController {}

class 
UserModel implements MyModel {}
// and so on...
?>

EDIT: What I forgot to mention was the sense of each of the three classes. The Models are Classes that provide access to data, like userlists, news etc. pp. The Controllers are classes that provide the "functionality" of the application. They manipulate and order the data they receive from the Models. The third type of classes, the Views, create the actual output. In web applications, they would create HTML or JSON code to send to the user.

Well... any opinions are welcome
It depends on the scale of the project tbh. If its a simple script, then there's no point, but if you're creating a large scale project, and you need it to be easily extensible, with optional plugin functionality, then I'd pick MVC.

I'm currently working on a non-LFS related project and I've gone for a full MVC-style. Unfortunately I've found that most of the existing frameworks are still total overkill - which is often why people mistakenly say that the whole concept is overkill.

I've personally found the Zend framework to be the least bloated so far (I personally don't like Solar, Cakephp, etc.), but it's horrifically slow, not to mention written in collaboration with Zend.
Yep, Zend Framework provides some great solutions, but tbh I personally would not use Zend_Controller and Zend_View, but I would create my own classes that only have the stuff included that I need. I mostly like the Zend_Db class, because its only a lightweight layer on top of PDO that adds a few very nice features, not a huge ORM monster like for example the Database component by ez (http://components.ez.no).

Oh, by the way, does PDO / Zend_Db support prepared statements for the mysql library? I know MySQLi does, but have no idea if it also works with libmysql only.

Greets
Quote from the_angry_angel :I've personally found the Zend framework to be the least bloated so far (I personally don't like Solar, Cakephp, etc.), but it's horrifically slow, not to mention written in collaboration with Zend.

Ever looked in to CodeIgniter? I've not used it much due to lack of time and experimenting with other areas -- PHP to Java and back through ebXML & JBOSS based web services anyone? -- but it looks like it will do everything I'd need to do without too much guff. And you can easily override core functionality without having to patch the changes in everytime you upgrade CI.

To the original question; It depends on the app. If another pattern would fit the goal better then I'll use that.

For the most part though, MVC serves my needs just fine for creating typical interactive apps.
Yes, I've taken a look at CodeIgniter and tbh I wasn't overly impressed; one of their helper functions to strip bad input was utter bollocks, and after finding that I ran away quite quickly.

What I should've made clear was that I've actually opted to create my own, very simple, MVC framework for the project I mentioned above. I have, however, taken a few things with me from the various other ones I've looked at / used over the years. For instance I quite like the Zend_ACL (which uses a roles type interface - which I thought was interesting and slightly different), I've taken a few ideas from Cake, and Solar as well. Basically I want to avoid bloat, wanted to avoid generating code magically (because, quite frankly I think its a bad idea), and I wanted to avoid litering my app directory tree with xml config files.

So yes, MVC is A Good Thing(TM), but if you want something quick and lightweight, you seriously need to consider rolling your own atm
Quote from the_angry_angel :[...] So yes, MVC is A Good Thing(TM), but if you want something quick and lightweight, you seriously need to consider rolling your own atm

In essence, this is also what my opinion is right now. But I dont think magic code generators like ruby on rails are bad all in all. it can really help building a basic construct for php applications. but to be honest, I also dont like the solutions that are currently in the market... speaking of ruby, cake and others here. I think I would write my own if this really was needed.

On the other hand, I can see your point. It is useless to always generate code via a generator like ruby when you have a firm basic construct that you can build all your projects on. this construct may need some tweaking for each project, but basically is the same.
Quote from the_angry_angel :It depends on the scale of the project tbh. If its a simple script, then there's no point, but if you're creating a large scale project, and you need it to be easily extensible, with optional plugin functionality, then I'd pick MVC.

^ What he said, but I would add that in any medium sized project, MVC is not an option, but a must.

FGED GREDG RDFGDR GSFDG