[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 632
  • Last Modified:

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
0
hefterr
Asked:
hefterr
  • 8
  • 5
  • 4
  • +1
2 Solutions
 
Jones911Commented:
Setup a maping in CFadmin to point to the CFC's
0
 
hefterrAuthor Commented:
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
0
 
Jones911Commented:
Attahced is a screen shot.

Yes if you want to reference one location from mutiple webroots it's the only way.
Capture.JPG
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
_agx_Commented:
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
  ...
0
 
_agx_Commented:
from mutiple webroots

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


/Root/Store
storeprograms.cfm
myStoreCFC.cfc

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

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

     <cfinvoke component = "store.myStore.cfc" ....>
0
 
Jones911Commented:
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.
0
 
_agx_Commented:
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.
0
 
hefterrAuthor Commented:
@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
0
 
Jones911Commented:
Yes I think you have got it now.
0
 
_agx_Commented:
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.

0
 
_agx_Commented:
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" ...>


     
0
 
hefterrAuthor Commented:
@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
0
 
gdemariaCommented:

(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.


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

It's just the name of your local folder
     ie  c:\Coldfusion8\wwwroot\myapproot.  

Dot notation is just like a relative url except you use dots "." instead of "/"  (and leave off the .cfc extension)

web root:           c:\Coldfusion8\wwwroot\
cfc file:                c:\Coldfusion8\wwwroot \myapproot\myrootCFC.cfc
relative url:         /myapproot/myRoot.cfc
dot notation:      "myapproot.myRootCFC"

ie
       <cfinvoke component="myapproot.myrootCFC" ...>
0
 
hefterrAuthor Commented:
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" !!.

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 8
  • 5
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now