views:

45

answers:

3

Hello,

I'm trying to get to grips with the MVC structure and trying to decide where my files should go.

I have a php script which reads an image from a non-web accessible location and outputs it.

Does it belong in the Controller or the View?

Likewise, should a script that loads a smarty template (from the view) and sets values and output it be within the Controller or the View?

Thanks for your help!

A: 

Both your examples sound like Model logic to me, but the second example is a little more fuzzy. A template is a View but setting values is probably Model logic if it's non-trivial.

Your View should invoke a Model to get stuff it needs, and the Controller should be deciding which View to display and instantiating the right Model to hand off to the View.

If you can treat your proxy image script as a Model then just invoke it in the View.

gazarsgo
Nice explanation, thanks for that, much appreciated!
JohnK
A: 

Only Model in this situation.

Alexander.Plutov
Thanks, I've taken your advice.
JohnK
+1  A: 

I Second. Model because controllers get fat so fast.

It should be a model as only Models should be allowed to know where data can be found and how they should be access (filesystem in your case). Also data conversion is best done in a model.

Dare to output compressed JPGs instead 10MB+ BMP-files on the fly? If your server can manage it your $ImageModel->outputAsJPEG() could be called in the controller, skipping viewscripts alltogether or delegated to the viewscripts/smarty functions.

Christoph Strasen
Thanks for the suggestion, I've taken your advice!
JohnK