1 person found this helpful
A better way is to not submit forms to cfc pages. Instead, submit them to cfm pages which call the cfc pages.
ok...I was simply following an article written by Ben Forta. I am fine doing it another way...Do you have an example somewhere?
My approach would be:
Use cfobject or createobject to get access to the methods in the cfc.
Call the two functions separately. You can use cfset or the equivalent cfscript code for this.
Process the returned information according to your requirements.
Thanks for pointing me in the right direction. I believe I have it figured out. I would appreciate any feedback on my code though
, since this is my first cfc. I will see if I can attach.
One thing I am still fuzzy on is the need for init().
Cannot seem to attach code...
1 person found this helpful
the init() is not needed.
But the ColdFusion Component does not have the automatic constructor method that many other Object Orientated Systems do. It is the psudo constructor area. Which is code outside of any <cffunction...> block. Code placed here, ususally at the top of the <cfcomponent...> block, will be ran for every invokation of the component. But one can not provide any parameters to this function.
Thus, with a need for a constructor method, the ColdFusion community as set on a standard of the init() function. That can be called when one invokes the component, to initilze the object with desired parameters.
OK...I get it (me thinks)....So it is a good practice to create an init
function in every cfc even though it is not needed as I could place code inside the init that would fire every time the cfc is instantiated.
Thanks you have been very helpful. I am attempting to get more oop oriented and separate my cf code more logically (MVC and such)
Well, I wouldn't create one if I did not need it in a specific Component.
But if your component needs one, the CF community standard is to name it init() so the chances are better that your code would be understood by others if you used init() rather then start() or constructor() or some other random function name.
Note that when using CF9's Hibernate integration, init() methods are treated as "proper" constructors, in that they are called automatically when an entity is created.
So using init() is moving away from being a de facto standard approach to this, and moving more towards an actual "official" implementation. If that makes sense.
If I have a CFC that will have stateful instances, I'll always implement an init() method, and always call it when I use the CFC. Even if all the init() does is "return this". I'm not sure there's really a good reason for doing this, though, I have to admit.
For CFCs that are simply a collection of like-minded functions, I don't bother.