Copy link to clipboard
Copied
Hi,
I am starting to get to grips with CF and have a few questions about using CFC's
At present I have a News module which has 3 major functions
-add news
-delete news
-update news
I have CFC with 3 methods, add, delete and update. What is the best practice for my cfm files
1) have 3 seperate cfm pages each calls the method it requires
2) have one page index.cfm with a case to output the form required (url.action=add, url.action=update, url.action=delete)
3) same as above but the forms are included in the method (lots of HTML in my CFCs)
They all work, 1 has more cfm pages, 2 has one but is a bit harder to read, 3 has one CFM also and keeps the CFM really clean but had loads of HTML in the CFC (a bad thing?)
I would be intersted in opinions on the best way to work.
Thanks,
H.
Copy link to clipboard
Copied
Choose the method that is both simplest, and allows the most flexibility for changing requirements.
Copy link to clipboard
Copied
Hi,
I mainly use the first option, as to keep my sources easy to read (even for other people ! )
You could also write a 4e method in the CFC, which does the logic for you :
MutateNews: receives all necessary params to execute either method and the action param mentioned in point 2.
Then you could do something like this :
switch(action) {
case "add" :
call add news method
break;
case "update":
call update method
break;
case "delete":
call delete method
break;
default :
return "no such action";
}
In this case you would have but one action page to call, which in turn calls the MutateNews method.
It is useful in some cases but ultimately it is up to you which method you prefer. Neither is worse then the other.
Cheers,
Bert.
Copy link to clipboard
Copied
As usual, there is no "one true answer." It's a trade-off, and it comes down to this:
Given that there is no "bright-line rule" to be found here, my best advice is simply: "whatever you do, plan what you do, and maintain that plan throughout the service-life of the application." (Most likely, the application's tenure at the company will considerably out-live your own tenure at the same company, so your plan serves many distinct purposes.) Contemplate your next move before you make it.