[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Referencing CFCs from different Folder in a Site

Posted on 2011-03-03
18
Medium Priority
?
624 Views
Last Modified: 2012-05-11
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
Comment
Question by:hefterr
  • 8
  • 5
  • 4
  • +1
18 Comments
 
LVL 19

Expert Comment

by:Jones911
ID: 35032246
Setup a maping in CFadmin to point to the CFC's
0
 
LVL 1

Author Comment

by:hefterr
ID: 35032360
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
 
LVL 19

Accepted Solution

by:
Jones911 earned 1000 total points
ID: 35032402
Attahced is a screen shot.

Yes if you want to reference one location from mutiple webroots it's the only way.
Capture.JPG
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 52

Expert Comment

by:_agx_
ID: 35032406
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
 
LVL 52

Expert Comment

by:_agx_
ID: 35032411
from mutiple webroots

Are you using 2 web roots or just subfolders?
0
 
LVL 19

Expert Comment

by:Jones911
ID: 35032415
This will work:


/Root/Store
storeprograms.cfm
myStoreCFC.cfc

<cfinvoke component = "room.store.myStore.cfc" ....>
0
 
LVL 52

Expert Comment

by:_agx_
ID: 35032423
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
 
LVL 19

Expert Comment

by:Jones911
ID: 35032438
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
 
LVL 52

Expert Comment

by:_agx_
ID: 35032481
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
 
LVL 1

Author Comment

by:hefterr
ID: 35032582
@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
 
LVL 19

Expert Comment

by:Jones911
ID: 35032596
Yes I think you have got it now.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 35032665
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
 
LVL 52

Expert Comment

by:_agx_
ID: 35032871
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
 
LVL 1

Author Comment

by:hefterr
ID: 35032875
@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
 
LVL 39

Expert Comment

by:gdemaria
ID: 35033084

(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
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 1000 total points
ID: 35033131
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
 
LVL 1

Author Comment

by:hefterr
ID: 35038250
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
 
LVL 52

Expert Comment

by:_agx_
ID: 35038322
I think everyone contributed on this one. So a split sounds good.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question