Asking about MVC!

Hi.

Is MVC in PHP difficult to learn? Do I need a Framework to do MVC? Where can I learn MVC?

Regards.

is it hard? NO!

The amount of time you invest in learning how to utilize it will more than payoff later when updating / changing your sites.

You dont need a framework per se, I suppose you could write your own. However I have found the frameworks I have used have only enhanced my knowledge of PHP as I have gone in and explored them deeply, and they have always been far better than anything I could write myself.

Codeigniter is by far my favorite, and the easiest (from what I have seen) to get started with out of the box.

Whether or not you use codeigniter, their article on MVC is TOP quality, and one of the best explanations I have seen on how to utilize it correctly (and most of their advice could be applied to any framework, not just codeigniter). You can find that here: http://codeigniter.com/wiki/MVC/

Ive found wikipedia’s articles on it to be good as well, though much more abstract.

The most important thing to think about is that the Model should be primarily your database interactions and some of the grunt work (many frameworks also implement ‘libraries’ ‘plugin’ or ‘helper’ classes to be able to do the grunt work and leave the model for ONLY database interactions. From what I can tell both are considered valid). Controllers are your go-between, they will detect input (such as post data) and handle where to direct it, as well as doing much of the validation, then retrieving you ‘views’ and sending those to the browser. And of course your views are your html files which will contain also a minimal amount of code (usually just foreach, a very small number of ifs and some variables) and they will output and format the information accordingly.

To learn mvc pattern you need some basic programming knowledge. MVC pattern can be implemented in any programming language. In your case you will need some basic php knowledge. You can check this PHP MVC tutorial for a basic understanding of the pattern. Then you should choose a MVC PHP Framework to develop real applications. Some of most popular are CodeIgniter, CakePHP, Zend and Symfony.

An MVC is a type of framework… a tool, if you will, like a car.

Learning how to use an MVC is like learning how to drive… it’s relatively simple, assuming you already know how to program… you just have to follow some rules.

Learning how to MAKE an MVC, on the other hand, is akin to BUILDING a car… not a simple task. I’ve been building one now for about 4 years!!!

An MVC is a type of framework? I was under the impression that Model View Controller is a pattern like Listener/Observer, and that many frameworks use MVC.

Yes, it’s a development pattern… but lends itself to use of a framework, just like EJB… sure you could code everything out yourself, but that would make it infeasible to implement on any significant scale… MVC was invented as a development framework (smalltalk), and has always existed in the context of MVC frameworks… I don’t know a single person who develops MVC apps outside the context of a framework (though I’ve worked on one from some Romanian contractor once… it was a DISASTER!!! LOL).