Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I Use CFINCLUDE or CFSAVECONTENT inside CFC

Tags:

coldfusion

cfc

It seems like the standard MVC approch (as it relates to ColdFusion) is to make the view files .cfm and do a CFINCLUDE inside of the cfc that ultimately processes the view.

Does this break the Object Orientation of cfc's?

Does this cause the CFML compiler to have to compile the view everytime?

Is there a strong reason to NOT make the view files themselves cfc's with a GetContent method?

like image 554
Tom Hubbard Avatar asked Dec 23 '22 07:12

Tom Hubbard


2 Answers

Does this break the Object Orientation of cfc's?

Achieving this vague "Object Orientation" of cfcs is kind of subjective. Forcing yourself into "everything must be an object" is going to force you into doing things with CF that will create extra overhead. I little compromise is needed to make sure apps are speedy and efficient. Don't worry about achieving some undefinable goal of being "object oriented". Make a more definable goal, such as achieving reuse of cfcs, or encapsulation of change. Trying to make views into objects isn't necessarily help you achieve those goals because every view will be different and probably not reusable.

Does this cause the CFML compiler to have to compile the view everytime?

Cfms are compiled and cached too. I've had several large forms consisting of tabs, where each tab is a separate cfm file. On the first load, they take a couple seconds to compile and display. On subsequent loads, the tabbed view is generated and displayed instantly. The same happens with cfcs.

Is there a strong reason to NOT make the view files themselves cfc's with a GetContent method?

I while ago I tried implementing my own framework just for the learning experience and I ended up with the cfinclude approach. From what I remember, what I found was that using cfinclude encapsulated things better and avoided the cumbersomeness of creating objects, passing around arguments needed for the view, worrying about objects being in the right scope, and avoided the extra overhead of creating view objects.

In the end though, I suppose this is one of those things you have to try yourself to figure out what approach is best for your situation.

like image 50
Jayson Avatar answered Feb 05 '23 16:02

Jayson


If you're interested in implementing MVC, you should check out the wide array of CFML frameworks that already make these decisions for you.

Try ColdBox, ColdFusion on Wheels, Mach-II, or Model-Glue. Or at least take a look at their source code and see how they handle it. :)

like image 27
Chris Peters Avatar answered Feb 05 '23 14:02

Chris Peters