1

I am trying understand how MVC should be applied in PHP. what i understand so far is **Model: **saves and receive data. **View: **request the data held by the model and present it. **Controller: **collect data sent by users and update the model with it.

my understand of MVC

is this correct cause its so confusing how many different implementation of MVC who seems to claim correct.

twist
  • 103
  • 8
  • yes, if you go by the [wikipedia](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) definition your interpretation is correct. – mister martin Oct 19 '16 at 17:39
  • It's not fully sufficient tho: user requests are not only to retrieve data from the model. User requests are not directly handled by a model but always by a controller (which is always in between the view and the model layer). – Benjamin Oct 19 '16 at 17:59
  • the only difference is to change the arrow from view->model to model->view – mister martin Oct 19 '16 at 18:08

2 Answers2

3

TL;DR yes, kinda.

This is what one would call "Model 2 MVC" or "Web MVC" as defined by Java community in early 2000s.

The main difference from "classical MVC" is in the way how view interacts with model, because in the classical approach the view would observe the model for changes in its state. The controller would alter the model's state and the view would receive signal, that the model' state changed. Which would prompt the view to request only the information, that was directly related to the change of state.

But the classical approach is not all that pragmatic for the web. Which is where Model2MVC comes in.

Due to web's request-response nature, you will end up with pairs of controllers and views. And each view will already know what its paired controller will alter in the model's state. And it doesn't need to observer anything, because it will need all the page data anyway.

I hope this helps.

P.S. The reasons why you see so many claiming to use 'MVC', which is completely different from this, is RubyOnRails - it used 'MVC' as marketing buzzword.

tereško
  • 58,060
  • 25
  • 98
  • 150
  • wow that really hummm... (what the word to use) enlightening!, not to ask too much, i would rely love to read an article by you on this if you would care to write one. – twist Oct 20 '16 at 19:24
-3

Model - Deals with database.Add update delete etc.

Views are presentation of data i.e html formatting e.g table ,div

Controller sits between model and views. It means controller receives data from user sanitize it ,validate it then pass it to the MODEL.tHEN MODEL RETURNS TO THE CONTROLLER WHICH INVOKES VIEWS.

Avinash Ware
  • 158
  • 11
  • you're talking about a model view presenter (controller is the middle-man), that is not MVC. – mister martin Oct 19 '16 at 17:36
  • 1
    model is layer and consist of services,Domain Objects,and Data mappers(sql) link for reading http://stackoverflow.com/questions/5863870/how-should-a-model-be-structured-in-mvc/5864000#5864000 – Linus Oct 20 '16 at 07:14