• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
why use models?

#1
[eluser]jtan[/eluser]
Why do we need to use Models when we can put all the functions and organize them with just Controller's functions?

#2
[eluser]bl00dshooter[/eluser]
[quote author="jtan" date="1293297848"]Why do we need to use Models when we can put all the functions and organize them with just Controller's functions?[/quote]

Why do we create lots of controllers when we can just create one? Why use MVC when we can do fine without it? Why...?

Because it's better this way. It's more organized and easier.

#3
[eluser]jtan[/eluser]
not that, you misunderstood me.

but so far the benefit i can see with using models is you can share the data across different views. is there any others?

#4
[eluser]jedd[/eluser]
[quote author="jtan" date="1293317119"]is there any others?[/quote]

jtan - you might want to read through the [url="http://en.wikipedia.org/wiki/Model–view–controller"]wikipedia article on model-view-controller[/url] architecture to get some good insights.

#5
[eluser]jtan[/eluser]
with lots of objects going around when adding the model method, is it common practice to have a separate sheet to list all the variables and objects?

#6
[eluser]nuwanda[/eluser]
Models allow you to use the same data functions for many controllers. Each controller calls the same model method, perhaps with different parameters which then return data.

Without models you'd be writing the same data retrieval code in each controller. Major headache.

Of course, I guess it's possible to have an app where each controller method accesses unique data.

#7
[eluser]SPeed_FANat1c[/eluser]
[quote author="nuwanda" date="1293631570"]Models allow you to use the same data functions for many controllers. Each controller calls the same model method, perhaps with different parameters which then return data.

Without models you'd be writing the same data retrieval code in each controller. Major headache.

[/quote]

Without model you could yet use libraries instead of models for the same goal.

#8
[eluser]nuwanda[/eluser]
Of course you can use a library (a class).

In CI, a model is an extended class, just as a controller is. If you want to create a library(a class) and load it in a model or controller, it'll work just fine.

Frankly, in CI, I create classes simply for one of their most powerful reasons: encapsulation.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.