Should I use CFINCLUDE or CFSAVECONTENT inside CFC

It seems that the standard MVC approach (as for ColdFusion) is to create .cfm files and execute CFINCLUDE inside cfc, which ultimately processes the view.

Does this disrupt the orientation of the cfc object?

Does the CFML compiler compile a view every time?

Is there a good reason NOT to make the cfc view files themselves using the GetContent method?

+4
source share
4 answers

Does this mean the orientation of the object from cfc?

Achieving this vague "Object Orientation" cfcs is subjective. By making yourself โ€œeverything must be an objectโ€, you will force you to do something with CF, which will create additional overhead. I need a little compromise to make sure applications are fast and efficient. Do not worry about achieving some indefinable goal - to be "object oriented." Make a more specific goal, such as reusing cfcs or encapsulating changes. Attempting to pretend objects will not necessarily help you achieve these goals, because each view will be different and probably will not be reused.

Does this mean that the CFML compiler needs to collect the view every time?

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

Is there any good reason NOT to do the cfc file representations themselves? GetContent method?

I back then tried to implement my own training-only infrastructure, and I ended up with the cfinclude approach. From what I remember, I found that it is better to use cfinclude in encapsulated things and avoid the cumbersomeness of creating objects by passing the arguments necessary for the presentation, worrying that the objects are in the right area and avoiding the additional overhead of creating view objects.

In the end, I believe this is one of those things that you should try to figure out yourself which approach is best for your situation.

+6
source

If you are 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. :)

+4
source

Do not blindly follow a pattern or methodology just because someone suggested it. Look at the needs of your site and pay attention to your own preferences, paying attention to someone who supports the code in the future.

In particular, I use CFC to encapsulate the interaction with the database. I follow the MVC pattern because separating view code from model code is a very good idea, it is less important whether CFCs are the correct OO rules.

I use cfincludes in many places to reduce redundancy at my presentation level.

I implemented the controller part of my template using a custom structure (I created the controller), then became smarter and used MachII, Fusebox and Model Glue. Each of these frameworks supports / encourages the use of CFC views, etc., or better states that each of them supports good design and separation of concerns.

Find good templates, decide what works for you, implement and document.

+1
source

CFInclude will not bind your CFC portability anymore by linking it directly to CFM.

0
source

All Articles