Welcome Guest, Not a member yet? Register   Sign In
What's your opinion on where models are executed: controllers or views?
#1

[eluser]danbirlem[/eluser]
I think the best practice is to pass variables through views from controllers. What about you?
#2

[eluser]Ben Edmunds[/eluser]
Dan,

I think it is pretty much agreed upon that proper MVC structure is to never make a call directly to a model from a VIEW.
#3

[eluser]frist44[/eluser]
[quote author="Ben Edmunds" date="1269991612"]Dan,

I think it is pretty much agreed upon that proper MVC structure is to never make a call directly to a model from a controller.[/quote]

Can you clarify this? I'm under a very different impression...
#4

[eluser]danbirlem[/eluser]
[quote author="Ben Edmunds" date="1269991612"]...never make a call directly to a model from a controller.[/quote]

Why? It would seem natural to collect the data and pass through to a view from the controller. Using a model in the view seems redundant.
#5

[eluser]frist44[/eluser]
[quote author="danbirlem" date="1269992179"][quote author="Ben Edmunds" date="1269991612"]...never make a call directly to a model from a controller.[/quote]

Why? It would seem natural to collect the data and pass through to a view from the controller. Using a model in the view seems redundant.[/quote]

This is how all of our applications work. I look at the controller as sort of the central brains of everything. Getting data from the model, and then passing to the model. If you start calling models from views, there's a hodgepodge of functions that are generally hard to track down and debug in a larger application. The folder layout is already spread out enough. When thinking about data, I like to know exactly where to look before I look and having that hard line of where data comes from helps with that.
#6

[eluser]danbirlem[/eluser]
[quote author="frist44" date="1269992347"]I look at the controller as sort of the central brains of everything.[/quote]

Well put!
#7

[eluser]Ben Edmunds[/eluser]
Sorry guys!

Meant to put
Quote:never make a call directly to a model from a VIEW.

Sorry for the typo
#8

[eluser]frist44[/eluser]
haha ok. Phew....I was like what in the world have I done???
#9

[eluser]Ben Edmunds[/eluser]
And to clarify.

Making all the model calls through the controller is how every CI app I have ever made is programmed (except for the rare partial) and how every professionally coded CI app I have every seen the code for is done.
#10

[eluser]Ben Edmunds[/eluser]
Hahaha, sorry about that frist! Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB