Solved

Coldfusion Component Paths

Posted on 2011-09-20
9
430 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ColdFusion MS SQL CSV Impport 10 69
CFMail not sending messages with queries 5 54
populate select menu with array from another select menu 3 78
On Submit return to same spot 7 100
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 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