But do all people maintain MVC in real manner??? The major misconception the people have is about the role of Model in MVC. I read many tutorials of Ruby on Rails, Zend Framework, CakePHP and Symfony. Many of the tutorials explain the role of Model as to access data from database. That means Model would be responsible for providing and updating of data into the database!!! All the business logic would be handled by the Controller!!!
It is a simple way, but would be fare only for small scale applications which do only CRUD (Create, Read, Update, Delete) operations. Then, what about large applications where business logic is much complex? Is it a good idea to encapsulate all business logic in Controller?
I recently read some blog posts such as:
ActiveRecord sucks by Kore Nordmann,
ActiveRecord sucks, but Kore Nordmann is wrong by Mike Seth,
ActiveRecord does not suck by Bill Karwin and
Fat Models and the Data Access Layer by Dave Marshall
Bill Karwin and Dave Marshall explains actual implimentation of Model. The Model is a business logic of your application not only the database access layer. Active Record (in RoR, Cake, Symfony) or Table/Row Data Gateway (in Zend Framework) should be used as a part of model not as a model. Your all business logic should be encapsulated in Models only.
One of the strongest reasons for following MVC is reusability. Think about the case when you want to port your PHP web application to desktop application using PHP-GTK. If you have followed correct MVC architecture then you can easily reuse the same Models of web based application into GTK based application. If you have encapsulated your business logic in controller, then you have to rewrite all the code again for GTK!!! It would simply kill DRY (Don't Repeat Yourself) principle!!!
I am using Zend Framework since its 1.0 release. At the beginning I read lots of tutorials about it and I was in the same misconceptions about the Models. Then I had taken a look around the code base of Magento Commerce. As I told in my previous post, Magento is built on Zend Framework and follows MVC architecture. (I noticed that Magento uses many ZF components but does not use Zend_Controller and Zend_View for its MVC because of its own custom patterns. But the implementation is quite similar to Zend Framework.) I'd noticed that MVC is followed in really nice way and provides very much flexibility for customization. It is very good example for enterprise application design.