• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 438
  • Last Modified:

Coldfusion Component Paths

I have stayed away from using Coldfusion components do to the fact you need to have a full path to the web root on down. Is there an easy way to develope on a local machine with one path localhost:8500 ... and then modify the code so that when I put it on the server I don't have to change every path that calls the component... what a pain in the a**.

I have seen the expand path option but that seems to have "\" and I believe you need to have a dot structure to the correct folder.

I am developing in a shared enviroment so mapping is not an option.

Any help would be greatly appreciated.

Any hel
0
jasch2244
Asked:
jasch2244
  • 5
  • 3
2 Solutions
 
gdemariaCommented:
Your folder structure within your webroot will likely be the same for your dev server and your production server.  It doesn't matter what path is ABOVE the webroot.   For example...

dev machine..

D:\mywebsites\wwwroot\library\cfc\

live machine

C:\inetpub\websites\liveroot\library\cfc

In both cases, the path to your cfc would be   "library.cfc"

But to answer your question another way, you can replace that with a variable

request.cfcPath = "library.cfc"

and just use the variable in the component call instead
0
 
jasch2244Author Commented:
I don't understand what you mean.. If my cfc is in a folder named cfc how would a variable request.cfcPath automatically find it? Is it a built in function with coldfusion? And if so is that the best way to do what I'm asking (I'm nervous it would add additional processing from the server therfore delay an invoke. Capish?
0
 
gdemariaCommented:

First, let me reiterate, I don't see how it is necessary to use a variable.   If you put the cfc files in a folder called CFC, then simply refer to it  as    ("cfc.myfile","mymethod")

This should be the same on the dev server and the production server, so no change would be needed.

If you need to use a variable for some reason, in your application.cfc/.cfm file you would define the variable

<cfset request.cfcPath = "cfc.">

In your cfc call you would use it...   ("#request.cfcPath#myFile","myMethod")

In the application.cfc/.cfm file on each server has it's own value set for the path, so all the files within the server will use the correct path for the server.

When you update from dev to production, typically you will not also copy the application file as it is server specific, so no change is necessary.   If you do copy up the application file, just be sure to set this variable for the server before copying it.

> what I'm asking (I'm nervous it would add additional processing from the server therfore delay an invoke

Processing a variable will not add any time to processing speed at all.


If you ask for my recommended approach it would be this...

In your application.cfc file, you should instantiate your cfc file and then use the variable from then on.  Then you do not call the path anywhere within your files, you only refer to the variable.

Like this... in your application.cfc/.cfm file, setup your cfc file like this...

 <cfset application.orderCFC = createObject("component","library.cfc.orderCFC")>

Then run methods like this...

<cfset theResult = application.orderCFC.createOrder(customerID)>

This will save processing time because you initiate the cfc only once and it stays until the application scope expires...

As for my preference this would be #1, #2 would be the path I described at the top and #3 would be the variable approach (last choice)


0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
devilJinKazamaCommented:
gdemaria explained it really well. just to finish off

if you are using application.cfm you can surround it with an if condition so its not set everytime , only on restarts

<cfif NOT structKeyExists(application,"orderCFC")>
     <cfset application.orderCFC = createObject("component","library.cfc.orderCFC")>
</cfif>

if you are using application.cfc you would just put it inside the onApplicationStart() method
0
 
gdemariaCommented:
good addition devil, thanks
0
 
jasch2244Author Commented:
Sorry I'm still confused.

gdemaria:

I understand you want me to create a variable in an application.cfc file:

<cfset application.orderCFC =

• I understand the <cfset application.orderCFC as it is naming the variable
• the second part: createObject("component","library.cfc.orderCFC")> I'm assuming the createObject does what it says it's going to do but not following the library.cfc.orderCFC... is this from the root down?

Also if I have the CFC (folder name) in the root you mentioned "then simply refer to it  as    ("cfc.myfile","mymethod")"  So I don't need to know the root folder name to referrence that path? What if I'm calling the CFC folder from 5 folders deep in the application? I think that would be easier than doing the application.cfc as you mentioned.. my confusion lies in the Ben Forta books where he states it has to have the whole path root on down. Thanks in advance :)
0
 
gdemariaCommented:
> What if I'm calling the CFC folder from 5 folders deep in the application? I think that would be easier than doing the application.cfc as you mentioned.. my confusion lies in the Ben Forta books where he states it has to have the whole path root on down. Thanks in advance :)

From the root means only from the top folder down, it doesn't matter where you are within the folder structure, the path is always the same.

d:/inetpub/wwwroot/cfc/

Would be referred to as "cfc.myCFCfile"  regardless of where it is called from, anywhere.   You start from the root folder and work your way DOWN only...

That's why I say this is the easiest way, all you have to do is put the cfc in a folder that is the same (relative to the root) on dev as it is on production...

If you put the cfc files all in a folder called cfc under the root, and you do this on both servers, then you are good to go... just refer to it as   "cfc.myCFCfile"   ...   where mycfcfile is the name of the xxx.cfc file.

0
 
gdemariaCommented:
> the second part: createObject("component","library.cfc.orderCFC")> I'm assuming the createObject does what it says it's going to do but not following the library.cfc.orderCFC... is this from the root down?



This is the same concept as I described above.   Whether you create it into a variable or invoke it, etc.   The path is always the same... start at the root and work your way down...  

If the myCFCfile.cfc file is put in the root, then you can just refer to it by the file name

   createObject("component","myCFCfile")
0
 
jasch2244Author Commented:
Thank you for your patience :)
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now