Copy link to clipboard
Copied
I am creating my first RESTful cfc which will allow a legacy system to interact with a more current system. There are some "configuration" variables that need to be available to a couple of functions in the cfc. These variables are mainly for disk paths and an API key. What is the best practice for setting these variables in my RESTful cfc? Should I just declare them at the beginning of the component outside the functions in the variables scope? Do I need an init function? If I use an init function how does it get called when the other functions are only called via REST?
Copy link to clipboard
Copied
I think you can declare them in the beginning of the component prior to any functions. You can include an init function, and just call it the same as you would call any other function.
<cffunction name="init">
<cfreturn this />
</cffunction>
<cfset tmp = path.to.component.init()>
I haven't worked with that, myself, but I've seen lots of code do that.
HTH,
^_^