Welcome Guest, Not a member yet? Register   Sign In
how to use model?
#3

[eluser]Frank Berger[/eluser]
Quoting from the MVC entry on Wikipedia:

Quote:[MVC] As a design pattern
MVC encompasses more of the architecture of an application than is typical for a design pattern.

Model
The domain-specific representation of the information on which the application operates. Domain logic adds meaning to raw data (e.g., calculating whether today is the user's birthday, or the totals, taxes, and shipping charges for shopping cart items).
Many applications use a persistent storage mechanism (such as a database) to store data. MVC does not specifically mention the data access layer because it is understood to be underneath or encapsulated by the Model.

View
Renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes.

Controller
Processes and responds to events, typically user actions, and may invoke changes on the model.

Or in other words: The model has all the functionality, intelligence and integrity to handle all the (business) logic and data flow. All of that is now in your controllers (as you're not using models). Strictly spoken, a controller in CI wouldn't even need a database connection. I see this as commodity to the developers.

Your controllers will get very small, most of the data-handling stuff is done in the model. Advantages are that you have more portable code (if you agree on a common interface for your models, like for example always having a get, getlist, save, exists method) your controllers will all become pretty much the same, just changing names and model-calls, enabling you to create a controller much faster. As well with using models the Model-intelligence can be shared across several Controllers, without implementing a function twice.

Or as an alternative view: if you ever needed to copy-paste a piece of code (or logic) from one controller to another without changing it, you should have implemented that piece of code (or logic) as a model or as a library

The MVC pattern enables you to think in separated Development steps. You can think about the Presentation, the data and the interaction logic in separate Files, Logic, Steps and People/Teams if you must.

I usually start with the model, and then quickly implementing a test-controller to move on to implementing the needed controller(s) with dummy views, doing the real views last, as the html-design is usually done in my case by somebody else. If I have a lot of ajax/javascript interaction then I develop that in parallel to the controller/view development.

Frank


Messages In This Thread
how to use model? - by El Forum - 10-12-2008, 09:14 PM
how to use model? - by El Forum - 10-12-2008, 10:41 PM
how to use model? - by El Forum - 10-12-2008, 10:55 PM
how to use model? - by El Forum - 10-12-2008, 11:42 PM
how to use model? - by El Forum - 10-12-2008, 11:54 PM
how to use model? - by El Forum - 10-13-2008, 12:06 AM
how to use model? - by El Forum - 10-13-2008, 12:51 AM
how to use model? - by El Forum - 10-13-2008, 01:05 AM
how to use model? - by El Forum - 10-13-2008, 01:20 AM
how to use model? - by El Forum - 10-13-2008, 01:28 AM
how to use model? - by El Forum - 10-13-2008, 02:10 AM
how to use model? - by El Forum - 10-13-2008, 02:43 AM
how to use model? - by El Forum - 10-13-2008, 02:53 AM
how to use model? - by El Forum - 10-13-2008, 02:59 AM
how to use model? - by El Forum - 10-13-2008, 03:04 AM
how to use model? - by El Forum - 10-13-2008, 03:08 AM
how to use model? - by El Forum - 10-13-2008, 03:17 AM
how to use model? - by El Forum - 10-13-2008, 03:34 AM
how to use model? - by El Forum - 10-13-2008, 03:43 AM
how to use model? - by El Forum - 10-13-2008, 03:49 AM
how to use model? - by El Forum - 10-13-2008, 03:54 AM
how to use model? - by El Forum - 10-13-2008, 03:55 AM
how to use model? - by El Forum - 10-13-2008, 03:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB