Solved

Coldfusion Component Paths

Posted on 2011-09-20
9
426 Views
Last Modified: 2012-05-12
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
Comment
Question by:jasch2244
  • 5
  • 3
9 Comments
 
LVL 39

Expert Comment

by:gdemaria
ID: 36571081
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
 
LVL 1

Author Comment

by:jasch2244
ID: 36571157
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
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 36571187

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
 
LVL 3

Expert Comment

by:devilJinKazama
ID: 36571265
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 39

Expert Comment

by:gdemaria
ID: 36571286
good addition devil, thanks
0
 
LVL 1

Author Comment

by:jasch2244
ID: 36571315
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
 
LVL 39

Assisted Solution

by:gdemaria
gdemaria earned 500 total points
ID: 36571335
> 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
 
LVL 39

Expert Comment

by:gdemaria
ID: 36571337
> 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
 
LVL 1

Author Closing Comment

by:jasch2244
ID: 36571345
Thank you for your patience :)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

746 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

13 Experts available now in Live!

Get 1:1 Help Now