Zend Framework - Do we really need to use Models?

I have been programming in PHP for almost 10 years now and recently just got into MVC. I tried a few MVC frameworks like CakePHP, CodeIgniter, and Zend Framework. I even programmed my own. I know most of us do not want to program our own MVC frameworks.

Do you really need to use models in MVC programming?

Now going through Zend Framework, I realized that we really do not really need models as the code used in models can easily be used in controllers. Now before the MVC experts say anything, please read on.

My question and answer is really pointed at other MVC beginners and I built a few MVC sites with Zend Framework with just controllers and views. The controllers even worked when I called certain libraries like Zend_Db into them.

So, for those learning MVC, if you find this programming concept overwhelming, concentrate on controllers and views first. Now, the bottom line is that for very simple websites, we do not need models, especially at the time when traditional PHP coders are learning MVC.

What about large scale websites?

Ok, NOW models may be needed. Being the business logic of the entire MVC concept, most of the programming should go here. When you see that your controllers are becoming very inundated with PHP code, it probably is the time to start using models.

Controllers are nothing but bridges between views and models.

From what I understand, controllers are supposed to be very slim, meaning that they should contain very little code. Your models can and should have most of the code. The controllers are simply a bridge that will tell the models to perform all of the processing and then whatever data the models produce will be ported over to your views as regular variables. If your controllers contain too much code, they will start looking like spaghetti code, which is one of the issues that MVC is supposed to avoid. If that happens, move your controller codes into a model.

Putting this all together for MVC beginners:

For small scale websites: If you are just learning MVC, stick with the views and controllers and learn them. For best practice, try to use a model if possible.

For large websites, start implementing your models and if you have code in your controllers that entails any type of processing, move them into the models and point their data to your views.

More by this Author


Comments 11 comments

optisol profile image

optisol 5 years ago from Chennai, India

Great Article!! Thanks for sharing..


hotwebideas profile image

hotwebideas 5 years ago from New York Author

Thanks, Optisol. Are you a programmer?


optisol profile image

optisol 5 years ago from Chennai, India

Yes.. We are a Programmers. please contact me - manikandan@ optisolbusiness.com or info @optisolbusiness.com


hotwebideas profile image

hotwebideas 5 years ago from New York Author

Excellent, I will, but what kind of programming do you perform?


optisol profile image

optisol 5 years ago from Chennai, India

We perform Open Source programming. We look forward to talk to you soon.


hotwebideas profile image

hotwebideas 5 years ago from New York Author

Excellent! What kind of Open Source programming? For what programs. Please list all you do...


optisol profile image

optisol 5 years ago from Chennai, India

We have programmers with expertise in PHP coding and also on frameworks like Joomla, Yii, Drupal, WordPress, Alfresco. We have done our custom implementations using Zend framework.

You can view our technology capabilities at optisolbusiness.com/tech/technology-capabilities


muayguy profile image

muayguy 5 years ago from Berlin, Germany

I had never used a framework before and the first one I tried was actually Zend Framework... I had a really hard time grasping many of its concepts, as it seems not even its community really understands models. I found and read several texts where the author over simplified models as just the logic related to the table. I actually began understanding MVC when I left ZF for a couple of weeks to try CodeIgniter...that was a complete different world for me, and much easier. When I went back to using ZF it was clear to me that the problem had been the overwhelming amount of stuff you first have to learn to get ZF to work (specially when Wordpress theming is all you had previously done in PHP). That being said, I think isolating the DB logic is the biggest achievement of the MVC pattern, and thus I wouldn't recommend placing all that logic within the controllers (based on portability, scalability and all that jazz). For smaller websites CMS's will usually do, or if you really need them, Zend Framework's libraries can be easily adapted to fit your needs without having to use it as a MVC framework


hotwebideas profile image

hotwebideas 5 years ago from New York Author

muayguy - Good points. I also, like you was using Zend Framework and I hated it, so I too switched to Codeigniter to learn and understand MVC and now I do, but I have no wish to go back to Zend Framework.

I also created my own MVC framework. Check my hub at http://hubpages.com/technology/Your-First-PHP-MVC-...


muayguy profile image

muayguy 5 years ago from Berlin, Germany

Yeah I know what you mean. CodeIgniter is pretty sweet,...I think you might like Kohana. I was told by several Kohana guys that it's the way to go if you really like CI... a little bit more featured and the same feel.


hotwebideas profile image

hotwebideas 5 years ago from New York Author

I have to try Kohana. Thanks for the tip!

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working