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

CFObject

LEGEND ,
Aug 05, 2006 Aug 05, 2006

Copy link to clipboard

Copied

Can someone point me to a good place to learn more about accessing a CFC in
an CFObject and how to pass variables to it. Also how to access the output
to use on a page.

--
Wally Kolcz
Developer / Support


TOPICS
Advanced techniques

Views

463

Translate

Translate

Report

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 ,
Aug 05, 2006 Aug 05, 2006

Copy link to clipboard

Copied

As a general rule of thumb, your first port of call for any question
regarding CFML usage should be livedocs. And the search button.

Start here:
http://livedocs.macromedia.com/coldfusion/7/htmldocs/00000304.htm

Follow the links on the page.

Having read that stuff, it should become fairly clear. If not... post
another question :-)

--
Adam

Votes

Translate

Translate

Report

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 ,
Aug 05, 2006 Aug 05, 2006

Copy link to clipboard

Copied

Sorry, I had looked at CFObject. I was confused on if you can do dot
notation to locate the CFC outside of the main directory. I was doing it
with CFScript and creating an object there, but I am a little lost on the
LiveDoc examples of how to use it.

"Adam Cameron" <adam_junk@hotmail.com> wrote in message
news:19ymzth287zla$.15muli16bwlhx.dlg@40tude.net...
> As a general rule of thumb, your first port of call for any question
> regarding CFML usage should be livedocs. And the search button.
>
> Start here:
> http://livedocs.macromedia.com/coldfusion/7/htmldocs/00000304.htm
>
> Follow the links on the page.
>
> Having read that stuff, it should become fairly clear. If not... post
> another question :-)
>
> --
> Adam


Votes

Translate

Translate

Report

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 ,
Aug 05, 2006 Aug 05, 2006

Copy link to clipboard

Copied

> Sorry, I had looked at CFObject. I was confused on if you can do dot
> notation to locate the CFC outside of the main directory.

Well the first example at that URL does it, so I should think it's OK (I
never use <cfobject>, in favour of always using createObject(), myself).

The computer will not blow up if you get something wrong. So a good thing
to do is to TRY your supposition, and see if it works. And if it errors,
usually the error messages are helpful.

My uninformed but educated (if that's not an oxymoron) opinion is that
<cfobject> should work exactly like createObject() does, and you'd use the
same dotted-path in <cfobject> that you would with createObject().

It would be easiy enough for you to put this to the test, I think..?

--
Adam

Votes

Translate

Translate

Report

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 ,
Aug 05, 2006 Aug 05, 2006

Copy link to clipboard

Copied

Ok, I cannot figure out how to locate the CFC using the CFObject. I tried
this:

<cfobject name="ListProjects" component="sf_main.components.SingleProjects">
<cfinvoke component="#ListProjects#" method="ListProjects"
returnvariable="LProjects">

But apparently that is all wrong. I used the example from the LiveDoc and
tried to modify it to work:

<cfobject name="quoteService" component="nasdaq.quote">
<cfinvoke component="#quoteService#" method="getLastTradePrice"
symbol="macr" returnVariable="res">

When I was using the CFScript method:
<cfscript>Projects=createObject("Component","sf_main.components.SingleProjects");</cfscript>

It found the component just fine, but I cannot figure out how to take the
info that is supplied by the CFC and display it on the page.
This CFC method does not need any arguments, but others do and I don't know
how to pass an argument through this.


Votes

Translate

Translate

Report

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 ,
Aug 05, 2006 Aug 05, 2006

Copy link to clipboard

Copied

Wally Kolcz wrote:
> When I was using the CFScript method:
> <cfscript>Projects=createObject("Component","sf_main.components.SingleProjects");</cfscript>
>
> It found the component just fine, but I cannot figure out how to take the
> info that is supplied by the CFC and display it on the page.
> This CFC method does not need any arguments, but others do and I don't know
> how to pass an argument through this.


<cfscript>
// create the component, located in mapped dir "CFC", in sub dir "boardfusion"
// the init() function inits the CFC & returns the CFC via "return this"
i18nUtils=createObject("component","cfc.boardfusion.i18nUtil").init();

// pass in current datetime as argument
now=i18nUtils.toEpoch(now());

// or you can name your arguments
now=i18nUtils.toEpoch(thisDate=now());

// no args
locales=i18nUtils.getLocales();

// args from the "form" scope
lang=i18nUtils.showLanguage(form.thisLocale);
country=i18nUtils.showCountry(form.thisLocale);
</cfscript>

Votes

Translate

Translate

Report

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 ,
Aug 06, 2006 Aug 06, 2006

Copy link to clipboard

Copied

LATEST
> Ok, I cannot figure out how to locate the CFC using the CFObject. I tried
> this:

If you browse directly to the CFC in question, the very first thing it
displays is its path.

It seems like you've sussed that out given, you can instatiate the CFC with
a createObject() call. I do have to wonder why - if you have a working
createObject() call - you are even bothering with <cfobject>, to be honest.
But anyway...

You create an instance of your object:

<cfobject name="myObj" component="path.to.the.cfc.file">

You call your method:

<cfset myResult = myObj.myMethod()>

Where "myMethod" is one of your <cffunction> names.

You call your method which takes arguments:

<cfset myOtherResult = myObj.myOtherMethod(someArgument=somevalue)>

Where "someArgument" is one of your method's <cfargument> names.

--
Adam

Votes

Translate

Translate

Report

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
Documentation