4

Read tens of articles on MVC, and right now, it's one mess for me. I am trying to do the right thing with my project, which I am rewriting from procedural php into oop, however, I am confused.

I am sure, Model should include all the business logic, which makes sense imo. Not too sure about View. Should I pass data to View, and render the template accordingly, or should the View just ask for data it needs (from updated Model)?

Read a lot about it on SO too, but it just got worse. Answers differ, and I am a bit lost.

What is the right explanation of MVC pattern? (Well, I know it could be different here and there, but the point should stay)

MVC 1

enter image description here

MVC 2

enter image description here

9
  • For avoidance of doubt, are you thinking about ASP.NET MVC or the more general concept of Model-View-Controller? Commented Dec 25, 2013 at 21:40
  • 2
    What language / platform are you using? MVC isn't possible for everything and is not a magic silver bullet to make your code more X. Commented Dec 25, 2013 at 21:43
  • I try to get it on general level, but I am rewriting web app in PHP Commented Dec 25, 2013 at 21:43
  • In that case it would be impossible to implement the proper MVC pattern fully. Commented Dec 25, 2013 at 21:44
  • 1
    Option 2 looks sane. Option 1 is how those crappy PHP framework are doing it so they can market something by saying: OMGWTFBBQAWESOME WE DO MVC, while all they are actually doing is using terms like models, controllers and views in a way that has nothing to do with MVC. Commented Dec 25, 2013 at 21:51

2 Answers 2

1

from my experience writing web application in ASP.NET MVC I can tell you it is great pattern! The Model is used to define your pure entities ( usualy entities that will be stored in a database ).

The Controllers handles user input for example when I first write the url of the site the request coming to the controller and the controller create model object and pass it to the view so the view can be rendered according to the model the controller pass to it.

hope I help you!

Sign up to request clarification or add additional context in comments.

Comments

0

Imho,... give a ** on this theoretical details. Just do it the way you feel most compfortable but definetly try to seperate concerns as there are:

  1. saving and retrieving raw data
  2. do programatical stuf with the data
  3. present the data

So assuming you have a user table I would create one class containing all the different mysql statements you need to create, edit, delete the users and so on. Then you need templates for example for user details page. It contains only html, css and so on and php variables and maybe some loops or ifs.

The rest of your code uses those two components and serves the result to the client.

1 Comment

This does not answer OP, but it is the correct answer. +1. Much better than trying to cram some paradigm / pattern into something it is not meant for and simply applying common sense.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.