SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: MVC pattern

  1. #1
    SitePoint Zealot
    Join Date
    Nov 2007
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MVC pattern

    I hope this is right forums for this.
    Well anyway, i'm starting learning zend framework, but i'm not sure if i understand really Model-View-Controller pattern.

    The only thing i think i got it corectly, is that View tells how the page will be displayed.
    But what about Model and Controller? I though Model means how data looks, like classes, database table, etc., and that controller is the "workhorse" , meaning it tells what exactly to do.

    So can somebody explains me a bit more about Model and Controller part of MVC?
    Tnx.

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Location
    Sydney, Australia
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Check the PHP Application Design forum. There is quite a few topics about it all there.

  3. #3
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are right about the view. It controls how the data is displayed to the user. In most MVC frameworks, the view is some kind of HTML template.

    The model contains the business logic. In web applications it usually means objects that represent the actual database tables. Logic about how the data is related, how it is stored, and how it is retrieved should be placed in the model.

    The controller ties things together. it is responsible for calling functions in the model to get the data it needs, and passing it to the view to be displayed. Most MVC design patterns recommend that you keep the controllers as small as possible. It's common for beginners to make these huge controllers with tons of business logic - most of that should be moved to the model. For example, if you have logic in your controller to sort data from the model - it's in the wrong place. You should write a function in the model that your controller can call to retrieve the data in whatever orer you need.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •