Improve company productivity with a Business Account.Sign Up

x
?
Solved

Coldfusion Component Paths

Posted on 2011-09-20
9
Medium Priority
?
440 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 2000 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

 
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
 
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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

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 …
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Watch the video to learn how one can deal with PST file corruption issue with an outstanding Kernel for Outlook PST Repair Tool easily. Using this tool, non-technical users can swiftly perform the repair process to restore their essential data witho…
A query can call a function, and a function can call Excel, even though we are in Access. This is Part 2, and steps you through the VBA that "wraps" Excel functionality so we can use its worksheet functions in Access. The declaration statement de…

589 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