Solved

Referencing CFCs from different Folder in a Site

Posted on 2011-03-03
18
598 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
Comment Utility
Setup a maping in CFadmin to point to the CFC's
0
 
LVL 1

Author Comment

by:hefterr
Comment Utility
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 250 total points
Comment Utility
Attahced is a screen shot.

Yes if you want to reference one location from mutiple webroots it's the only way.
Capture.JPG
0
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
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_
Comment Utility
from mutiple webroots

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

Expert Comment

by:Jones911
Comment Utility
This will work:


/Root/Store
storeprograms.cfm
myStoreCFC.cfc

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

Expert Comment

by:_agx_
Comment Utility
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
Comment Utility
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_
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 1

Author Comment

by:hefterr
Comment Utility
@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
Comment Utility
Yes I think you have got it now.
0
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
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_
Comment Utility
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
Comment Utility
@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
Comment Utility

(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 250 total points
Comment Utility
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
Comment Utility
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_
Comment Utility
I think everyone contributed on this one. So a split sounds good.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
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 …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now