Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC: models interacts with the view?

i know that everything is going through the controller.

but i often read articles that says something like this:

  1. user interacts with the view
  2. controller asks the model to change its state
  3. model notifies the view when its sate has changed

i dont get the 3rd one. why saying that the model notifies the view, when it actually is notifying the controller and the controller is notifying the view?

like image 820
never_had_a_name Avatar asked Apr 27 '10 04:04

never_had_a_name


2 Answers

That seems more like a desktop system and not a stateless system like a website.

But maybe it's talking about how some people like to query the models from the view e.g.

<?php foreach( $usersTableGateway->getUsers() as $user ): ?>
<?php echo $user ?><br>
<?php endforeach; ?>

I'm more of a fan of getting all the info in the controller (preparing the users array in the controller) and passing it to the view from the controller.

like image 129
Galen Avatar answered Oct 20 '22 16:10

Galen


MVC is a broad concept, and there are a wide variety of possible implementations. For example, Page Controller separates logic from the view, and so does Front Fontroller. Each MVC framework also has different methods for rendering model data in the view - Zend uses Two-Step for example.

You could possibly set up an Observer relationship between a view object and "the Model" (which in itself is a really complicated beast) but I think this aspect of the MVC pattern is more to do with the original context of the pattern - i.e. Galen's point above

like image 39
sunwukung Avatar answered Oct 20 '22 16:10

sunwukung