MVC question - block development

Permalink
Would really appreciate your help on a broad "C5 block development" question.

Question is: In C5 who puts what code where? View or Controller? (If this has been asked/answered/done, please slap me and point me at the right link; I couldn't find anything)

I get OOP and MVC, but it seems that much of my PHP code is descending into the view, mostly because blocks can support multiple views.

For example: I'm working on a block which displays a thumbnail - all the code is pretty much in the controller. But then it occurs to me that people might want to use a properly server side generated thumbnail of a different (but standard) size so my controller code, descends into the view templates to enable that flexibility at runtime.

There's more PHP in the view and less separation than before as a result and I'm not sure I'm doing it the best way.

Any examples of how best to move data/variables through MVC in C5 would be really appreciated.

Thanks once again

Ollie

olliephillips
 
12345j replied on at Permalink Reply
12345j
hereNT replied on at Permalink Reply
hereNT
In your example, I would put the logic for figuring out which image to use in the controller, and grab and assign the file object to the view with this->set('image', $fileObject) in your view() or onPageView() function, whichever function you're rendering.

Then in the view you can use that file object with the image helper to grab your thumbnail object at the size you need.

I think most of the image galleries work this way if you're looking for exact code samples...