Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Simple cfc mapping issue = I am a muppet

Guide ,
Jul 07, 2010 Jul 07, 2010

Right, there's something blissfully simple that I'm just missing here, but I've had by C# hat on for weeks and now have had to come back to CF and I've gotten stuck on a simple issue.

Yes, I've trawled Google and the search on here but I just can't spend any more time on this, so thought I'd post on here so someone can abuse my noobishness.

All I want is a simple mapping to a cfc directory for creating components. In order to avoid issues with mappings coinciding with physical directories, I've made them a little more unique but still nothing. My folder structure is currently thus (simplified):

/htdocs

  /badgers

    Something.cfc

  /quotenew

    index.cfm

What I want to do is to create an Application-level mapping (ie not in CF admin) to the cfc directory. My Application.cfc has the following lines at the top:

THIS.Mappings                = {} ;
THIS.Mappings["horses"] = 'badgers' ;

Then in /quotenew/index.cfm I have the following line:

<cfset a = createObject("component","horses.Something") />


But I'm getting the dreaded "Could not find the ColdFusion Component or Interface horses.Something." error.

I've tried everything I can think of but just can't figure out whether I've done something stupid or whether it would never work in the first place but as I said, I'm well out of practise. If anyone can point me in the right direction, I'd be most appreciative.

O.

890
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 07, 2010 Jul 07, 2010

Consider what values you'd put in to CFAdmin if you were making that mapping... and hopefully notice what you're missing from your statement in Application.cfc.

Hint: what's the first character of the logical path you'd specify for any mapping you make in CFAdmin?

Hint 2: it's in the docs: http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec0b63c-7fd5.html#WS0C5B9A8B-32B5-4db2-BC04-B76DF8823A34 (it took me a bit to find this, so I wouldn't be concerned if you missed it when you looked).

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 07, 2010 Jul 07, 2010
THIS.Mappings["horses"] = 'badgers' ;

More advice: be very careful when putting a saddle on that particular "horse".

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 07, 2010 Jul 07, 2010

Ah, it seems I'd done two things wrong.

Firstly, I needed a forward slash at the start of the mapping, which I believe is what Adam was getting at.

Secondly when doing mappings it seems you can only do them to physical directories, not CFC paths. At first I thought this was odd (and it's caught me out before) as if I can do createObject("system.cfc.classes.MyClass") then why can't I have a mapping to "system.cfc.classes"?

I can only assume this is to keep mappings generic - they can be used for physical directories and component paths so I guess the physical path is required.

All sorted now with this:

THIS.Mappings["/horses"] = 'g:\websites\mywebsite\htdocs\badgers' ;

Not quite as clean as I would have liked but still, if it's what needs doing.

Cheers Adam

O.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 07, 2010 Jul 07, 2010

Trying to do a mapping to a dotted CFC path is a bit of a circular idea, because CF needs to know where in the file system the CFC dotted path points to to be able to resolve it to a CFC file.

Also, as you touch on, CF mappings are for more things than just CFC resolution.

However you can use expandPath() on the RHS of the mapping, so I do this sort of thing:

this.mappings["/myapp"] = expandPath("/com/mycompany/myapp/");

One does not need to hard-code the entire path.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 07, 2010 Jul 07, 2010
LATEST

Ah yes, that's a little tidier - I've always been careful with getCurrentTemplatePath() as I know in certain circumstances (onRequestStart()?) it can cause unexpected behaviour if the calling page is in a subdirectory - however I do appreciate it works in this case.

UsingexpandPath() is certainly tidier, so I reckon I'll use that.

Cheers

O.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources