MVC pattern -> calling views direct from controller or from controller over a model? |
[eluser]F. Albrecht[/eluser]
Hi, after 6 successful projects with exciting ExpressionEngine I'm turning to CI to getting deeper in that MVC thing ![]() I've just played a little bit with the framework last days and read the docu. Yesterday I've got the book (David Upton) and read some pages. Therefore I have a question: In my understanding the MVC pattern is working as this: Code: Class My_controller In the book the view call happens via an indirect way like this: Code: Class My_controller Sorry for my simplified syntax ![]() I would prefer the first snippet but I don't know whether it is in the straightfoward MVC theorie? Or does it no matter? Thanks, 2nd
[eluser]wiredesignz[/eluser]
Strictly speaking your first example is the better method. See here for a good explanation of MVC. http://www.phpwact.org/pattern/model_view_controller
[eluser]Grahack[/eluser]
To me a model shouldn't be aware of the way it's displayed. Gonna read this page too anyway!
[eluser]maadmac[/eluser]
[quote author="wiredesignz" date="1199586447"]Strictly speaking your first example is the better method.[/quote] Agreed. As a general rule, you want to do all the db calls (via model) and output (via view) through the controller, which acts as "traffic" cop. CI doesn't even require models, you can actually do all your data processing in the controller... but it's good practice to get in the habit, anyway. As mentioned above, you want to decouple the model and view.
[eluser]Developer13[/eluser]
That's the biggest problem that I had with Upton's book was the fact that he gave his models output responsibility. No no no! |
Welcome Guest, Not a member yet? Register Sign In |