ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

Zend Framework - Do we really need to use Models?

Updated on May 12, 2011

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.

Comments

    0 of 8192 characters used
    Post Comment

    • hotwebideas profile imageAUTHOR

      Bruce Chamoff 

      6 years ago from New York

      I have to try Kohana. Thanks for the tip!

    • muayguy profile image

      muayguy 

      7 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 imageAUTHOR

      Bruce Chamoff 

      7 years ago from New York

      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 https://hubpages.com/technology/Your-First-PHP-MVC...

    • muayguy profile image

      muayguy 

      7 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

    • optisol profile image

      optisol 

      7 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

    • hotwebideas profile imageAUTHOR

      Bruce Chamoff 

      7 years ago from New York

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

    • optisol profile image

      optisol 

      7 years ago from Chennai, India

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

    • hotwebideas profile imageAUTHOR

      Bruce Chamoff 

      7 years ago from New York

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

    • optisol profile image

      optisol 

      7 years ago from Chennai, India

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

    • hotwebideas profile imageAUTHOR

      Bruce Chamoff 

      7 years ago from New York

      Thanks, Optisol. Are you a programmer?

    • optisol profile image

      optisol 

      7 years ago from Chennai, India

      Great Article!! Thanks for sharing..

    working

    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, hubpages.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://hubpages.com/privacy-policy#gdpr

    Show Details
    Necessary
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
    Features
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Marketing
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Statistics
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)