I don't think it would be possible to get a definitive answer to this. My guess is that the CFC doesn't *know* what path was used to instantiate it and from an encapsulation perspective it would make sense that this should be the case.

The reason I don't think it would be possible is that the same CFC could be instantiated using any of the following:

Assuming the a cfc called "mycfc" is in a directory called cfc under the webroot and there is one CF mapping called components and another called org.mydomain.components:

// Calling file in the local directory
createObject('component','mycfc')

// Calling file anywhere on the server - using webroot as base
createObject('component','cfc.mycfc')

// Calling file in the webroot directory - using relative pathing
createObject('component','cfc\mycfc')

// Using first CF mapping as base path
createObject('component','components.mycfc')

// Using second CF mapping as base path
createObject('component','org.mydomain.components.mycfc')

You might also be able to play around with virtual directories in web.xml and add some more possible paths.

Given the large number of different paths you could use to instantiate the same CFC and the usual rules of encapsulation (an object shouldn't be aware of or depend on it's environment), I wouldn't be at all surprised if there is no way to know what path was used to instantiate a component from within the component itself.

If you really need to do that, create an init() method or some such and pass the path in when instantiating.

Spike

Adam Cameron wrote:
(I'm resurrecting a thread from 2003, sorry)
Hi. So ages ago a namesake of mine was asking about getting the CFC *path* from within the CFC itself. Same-named people think alike (in my case it's nothing to do with "great minds", anyhow(*)), so here I am asking the same question... Now, I know that I can do this: getMetadata(this).name; That's OK, but if the CFC was instantiated using just it's filename, then that's all one gets back in that NAME property. I don't want to get what name the CFC was instantiated with, I want to get its full dotted path: "com.adam.rubbish.myComponent" or whatever (you know, as per the top of the API docs one gets when browsing straight to the CFC). It's been suggested to loop over the path value and do some jiggery-pokery to contrive a dotted name, but... really... seems like a lot of work for something that should "just be there"? I'm *guessing* there's a good (-ish) reason... probably something to do with CF mappings or... something like that. I guess what I'm asking is whether someone's found a way to just pull this value out by magic, or am I stuck with either not bothering, or looping over the path [etc]. Cheers for any thoughts.
--
Adam
(*) I hope person "jokes" at MY OWN expense are OK with you, Nando ;-)

This email contains confidential information. If you are not the intended recipient of this email, please notify Straker Interactive and delete the email. You are not entitled to use it in any way.

----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).

CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm

An archive of the CFCDev list is available at www.mail-archive.com/[email protected]

--

--------------------------------------------
Stephen Milligan
Code poet for hire
http://www.spike.org.uk

Do you cfeclipse? http://cfeclipse.tigris.org


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]


Reply via email to