Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Help with CreateObject()

Participant ,
Mar 04, 2008 Mar 04, 2008
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#");
TOPICS
Getting started
467
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 04, 2008 Mar 04, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 04, 2008 Mar 04, 2008
Oh I see, I didn't know that we can do that. thank you!!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 04, 2008 Mar 04, 2008
LATEST
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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources