latest reactions

spider
One way is to google for page which cont …
andy
you can find this tool here http://andy. …
Tjarko
Eej Walker, that's pretty cool, I will c …
Walker
Thanks for posting your thoughts. I modi …
Albert
Thanks !! …

Clicky Web Analytics
Use OpenDNS
ZERIGO DNS

Ultimate dns hosting based on pre-defined templates, DNS redirection and lot's more.

mxna feeds

CF101 Archive: September 2007 Object Oriented PizzaJob Opening for ColdFusion Developer at Arizona State UniversityMy New Experience Getting ColdFusion Builder 2 Console WorkingCF101 Archive: February 2007 Data Table GatewaysJob Opening for Sr. ColdFusion Developer in CA/ San Fernando ValleyColdFusion Supports HTTP Verbs PUT And DELETE (As Well As GET And POST)Best wishes for the new FuseboxCF101 Archive: January 2007 Data Access ObjectsOpen Source Conference For CFML DevelopersSkype Blocking Web Services with IIS, ColdFusion & RailoCF101 Archive: October 2006 Five Cool Things with ColdFusionGenerate a tag cloud from an RSS feed with ColdFusionColdFusion MeetUp: Cloudy with a Chance of Tests, with Mike HenkeReminder - Adobe CookbooksCF101 Archive: September 2006 A first look at FusionDebug

All files are strictly confidential: all information is classified.
© Copyright 2002 - 2012 mximize.com.
All right reserved.

Visit Carlos GallupaMXNA webfeed

Components, root, extends and how to tackle it.

Slash, Dot... and what's up with that Coldfusion root!!

When using components in Coldfusion you have probably run into the following problem.
For invoking or creating the object you need to pass an absolute path to the component, and
the absolute path is normally the path calculated from the root of your ColdFusion installation.

In my case: "c:\inetpub\wwwroot\"

So what's the problem then?? Well... because ColdFusion will calculate the path from the root and
no self-respecting hosting provider will have it's websites placed in the root... how do we access
the component then? With a mapping? Yes.. that's one way (the other is explained later) and probably
the only way, if you don't have control over your ColdFusion administrator. A mapping is a "logical" name for a certain directory path
on your server. For instance: my website runs in the "c\inetpub\websites\mximize\" directory and
a mapping "mximize" is pointing to this directory, i can now invoke a component
that is in the "cfc" directory of my application in thefollowing manner.

<cfinvoke component="mximize.cfc.mycomponent" method="mymethod" />

Problem with this is that you "hardcode" the mapping.. and we don't want that... oh wait a minute..
I don't want that!! Normally I create an application var for this that's in my "settings" variables.

<cfset applicaton.settings.mapping = "mximize">

This way I can invoke the component with a dynamic name, so when I switch from test/staging to a production
machine and the mapping name is different, I only have to change application variable.

<cfinvoke component="#application.settings.mapping#.cfc.mycomponent" method="mymethod" />

There is however a problem with this method of coding! When you use the extends attribute of a
component you CAN'T use a variable name for it :-( so with an extend you still have to hardcode the mapping
into your component, and I use the extends attribute a lot!!

<cfcomponent extends="mximize.includes.settings" />

So what would be the most ideal solution then? The most ideal situation is, if you can delete the
following mapping from your ColdFusion administrator's mappings.. "/" pointing to the "c:\inetpub\wwwroot" directory.
This mapping is the one that is responsible for having to code in the above way.. and that's a pain in the.. uh.. behind.

What happens when you delete this mapping, is that ColdFusion will magically see your website as his root!! You can now code
from the same rootpath that you probably code your images / stylesheets etc.. from. So it's no longer a mapping but just simply
calculate from the root of the site.. NOT the root of where ColdFusion was installed. An invoke and a extend would look like this.

<cfinvoke component="cfc.mycomponent" method="mymethod" />

<cfcomponent extends="includes.settings" />

Much much easier, and no mapping needed.

8187 viewed | Your opinion...  | del.icio.us | Digg it | Tjarko @ 29/11/05 8:40 cet


Reactions:

Leave your comment

Your name


Your url/website/link/email....


Some room for your reaction is placed here..



The answer to the ultimate question is?? (42 ;-))




URL en mail addresses are translated for you... life sometimes is that simple!!