Link to home
Start Free TrialLog in
Avatar of hefterr
hefterrFlag for United States of America

asked on

Referencing CFCs from different Folder in a Site

Hi,
I have a CFC reference question.
Say I have a site:
/Root
programs.cfm
myrootCFC.cfc

/Root/Store
storeprograms.cfm
myStoreCFC.cfc

My question is how do I get a program in Root/Store to CFinvoke a cfc in the root (myrootCFC.cfc) and how do I get a program in the root to CFinvoke a cfc in the root/store folder(myStoreCFC.cfc)

I'm basically questioning the "component" keyword:

<cfinvoke
    component = "component name or reference"    method = "method name"
    returnVariable = "variable name"
</cfinvoke

Thanks in advance,
hefterr
Avatar of Jones911
Jones911

Setup a maping in CFadmin to point to the CFC's
Avatar of hefterr

ASKER

Hi Jones911,
How do you do that in the CF Admin?  And is that the only way?  Can the references be done without updating the CF Admin for server?

Thanks,
hefterr
ASKER CERTIFIED SOLUTION
Avatar of Jones911
Jones911

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of _agx_
And is that the only way?  Can the references be done without updating

Depends. You often do need a mapping, but not always.

   <cfinvoke component = "myrootCFC" ....>

Here's how CF searches for that component

   http://livedocs.adobe.com/coldfusion/8/buildingComponents_27.html
   1. Local directory of the calling CFML page
   2. Web root
   3. Directories specified on the Custom Tag Paths page of ColdFusion Administrator
  ...
from mutiple webroots

Are you using 2 web roots or just subfolders?
This will work:


/Root/Store
storeprograms.cfm
myStoreCFC.cfc

<cfinvoke component = "room.store.myStore.cfc" ....>
I think you mean
     <cfinvoke component = "root.store.myStore.cfc" ....>

Though if the webroot was "/Root" then maybe just

     <cfinvoke component = "store.myStore.cfc" ....>
Yeah.  Room was a typo.

Yep you can drop the root if thats not a directory.  

<cfinvoke component = "store.myStore.cfc" ....>

Ill go from the root in a folder called "store" to the cfc called mystore

Also I left the .cfc in the invoke you don't need that.
Also I left the .cfc in the invoke you don't need that.

Ooops...me too.

Bottom line, unless you're using multiple web roots OR have multiple components with the *same* name in different directories, just using plain dot notation should work.
Avatar of hefterr

ASKER

@aqx
unless you're using multiple web roots

Not sure what you mean by this?  The site has 1 root and subfolders.  I'm tring to invoke a cfc in the root from a subfolder and visa versa.  Or between two subfolders.

@all:

I think the problem I'm having when accessing a cfc in the root (from a subfolder) is that on my local PC (using the CF Server), my root is really not the physical root.  the physical root is c:\Coldfusion8\wwwroot but my site root (locally) is c:\Coldfusion8\wwwroot \myapproot.

Soooo, If I understand what you are saying:
If I want to go from a root program to a cfc in a subfolder, then dot notation should work?

If I have a subfolder program invoking a different subfolder cfc, then mapping would be required?

A program in a subfolder invoking a cfc in the root just be OK (on my eal server using IIS).

Do I have this straight?

hefterr
Yes I think you have got it now.
Not sure what you mean by this?  The site has 1 root and subfolders.

Ok. That's what I thought.  My comment was responding to Jones911's suggestion you might have multiple roots. So I wanted to clarify. But you don't ... so the point is moot ;-)

If I have a subfolder program invoking a different subfolder cfc, then mapping would be required?

Depends.  It might be different w/IIS but technically you can call cfc's from anywhere using the full path.  Since c:\Coldfusion8\wwwroot \myapproot isn't really your webroot that means the full path to your cfc's would be:

       <cfinvoke component="myapproot.myrootCFC" ...>  OR
       <cfinvoke component="myapproot.store.myStore" ...>

But since you're probably trying to simulate a prod environment, my guess would be you'd want to create a mapping instead.

Btw: If you are simulating a prod environ. you can always store the base cfc path in a variable when your application starts.  That makes it easier to switch roots.  You just change 1 line of code.

        <cfset application.cfcRoot = "(whatever your root is)">

Then use the variable in your code.

       <cfinvoke component="#application.cfcRoot#.store.myStore" ...>


     
Avatar of hefterr

ASKER

@aqx:

I sorry if I'm a little dense on this (I have just had a cocktail :) but :

<cfinvoke component="myapproot.myrootCFC" ...>  OR
 <cfinvoke component="myapproot.store.myStore" ...>


I'm not sure what goes in "myapproot" in your examples (mapping?)

FYI.  I can map on my local PC but not on the server for root cfc's.
Thanks again,
hefterr

(no points)

The thing is that you just need to specify a path from your webroot down.

If this is your directory structure... with the .cfc file at the end::

 c:\Coldfusion8\wwwroot\mySite\library\code\myStore.cfc

and wwwroot is your web root then you specify it like this...

 <cfinvoke component="mysite.library.code.mystore">

and mysite is your web root then you specify it like this...

 <cfinvoke component="library.code.mystore">


So, whatever folders are under your web site's root folder, just connect them together, top-down, using dot notation.


SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hefterr

ASKER

Thanks to everyone as I really understand this now and everyone helped.  Not sure how to allocate points but I'll split them up.

@gdemaria - you indicated "no points" but you summary at the end really clicked it all together for me.

@agx : I like your idea of using the Application.cfc to define the root path for test versus production as these are each unique for each site/application

@Jones911 : Thanks for your help and explaining the CF admin mapping.  I never used this before (or new about it)

You guys deserve your "titles" !!.

I think everyone contributed on this one. So a split sounds good.