Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Coldfusion Component Paths

Posted on 2011-09-20
9
Medium Priority
?
435 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 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
How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

 
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

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

Question has a verified solution.

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

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

670 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