Welcome Guest, Not a member yet? Register   Sign In
Models vs. Controllers: help me understand
#1

[eluser]OldRodKS[/eluser]
I'm struggling to figure out the difference between models and controllers. Can someone help me out please?

For instance, in a standard login system, you have a login form (View obviously) and you have functions that verify whether the user is in the database or not and whether he has entered the right password or not. As I understand it, the controller is what contains these functions and calls them and the model is the actual database calls themselves, which are referenced in the functions of the controller.

Do I have that anywhere close to right?
#2

[eluser]TWP Marketing[/eluser]
Seems good to me. The controller acts on information and the model gets that information and presents it to the controller in a usable form.
The model can do more than just db access, but it's up to you where you want to do some of your data manipulation. I tend to massage my data in the model whenever possible and the controller is used for, well, controlling. Like sending data to the browser via views.
#3

[eluser]OldRodKS[/eluser]
Thanks for the reply. Sometimes I feel like I'm actually starting to figure this stuff out Smile
#4

[eluser]blekknajt[/eluser]
If we look at man via MVC:

VIEW is how he looks like - what he wear, what he speaks, how he moves.

MODEL is what he thinks and what he knows - but he must use senses to process input.

CONTROLLER are senses (to get input) and nervous system (to react).

So MODEL can be a brain in a whole, but one can can say, that only prefrontal cortex "counts" as model - and instinct with older parts of brain are part of controller.

For example extreme purist can took a date from model instead of using date() (because - maybe someday - he want to return it translated to martian).

It's not engraved in stone - all that matter is how it can help You in given project.

PS
Not exactly, but close: ellislab.com/forums/viewthread/157706/




Theme © iAndrew 2016 - Forum software by © MyBB