Skip to main content
Inspiring
March 4, 2008
Question

Help with CreateObject()

  • March 4, 2008
  • 3 replies
  • 509 views
I have just learned to use CreateObject() with CF.
I understand this syntax:
request.initFnds = createObject("component","#application.cfcroot#.system.loadFndSettings")
However,
I don't understand this (especially the string start with .init....), what is this for, can someone explain to me?
request.initFnds = createObject("component","#application.cfcroot#.system.loadFndSettings") .init(dsn="#application.mainDSN#",pID="#attributes.pID#",tempSecID="#attributes.secID#",
DocID="#attributes.DocID#");
This topic has been closed for replies.

3 replies

Inspiring
March 4, 2008
mega_L wrote:
> Oh I see, I didn't know that we can do that. thank you!!

Yes, it is called method chaining and can be used as a short cut. It is
often used as a defacto constructor since CF does not have the concept
of a constructor that one can pass arguments to. Developers create an
'init' method that returns an instance of the object created with the
arguments passed into that function.

mega_LAuthor
Inspiring
March 4, 2008
Oh I see, I didn't know that we can do that. thank you!!
Inspiring
March 4, 2008
It means that the cfc has a function called init that accepts arguments called dsn, pid, tempsecid, and docid. Another way to code this is:

Variable1 = createObject("component","#application.cfcroot#.system.loadFndSettings")

Variable2 = Variable1.init(dsn="#application.mainDSN#" pID="#attributes.pID#" tempSecID="#attributes.secID#"
DocID="#attributes.DocID#");

I'm not sure about the commas between the arguments, I rarely if ever use that syntax.