質問

If I don't want to do any mappings, is there another way to call a method in a component, which is "two levels up". Like so:

  service
     component_to_call.cfc
  mem
     pages
     handlers
        calling.cfc

this is my call from inside calling.cfc:

  <cfinvoke 
    component="service.component_to_call"
    method="do_the"
    param1="#renderedResults#" 
    param2="#taskByName#" 
    returnvariable="tamperedCode">
    </cfinvoke>

which throws an error that the service.component_to_call can't be found.

Qustion:
How can I call the component in the parent folder?

役に立ちましたか?

解決

Why don't you want to use mappings? That's a bit odd.

Anyway, just browse directly to the CFC you wish to instantiate, and it will output it's autogenerated API docs, the first thing will be its full dotted path. You can use that. However that is absolute, not relative.

What you cannot do is to somehow specify a relative path like one might with a file (eg: "../../fileInGrandparentDir.cfm"... one cannot do that with a CFC path.

An alternative is to make some directory that is an ancestor to both CFCs into a custom tag path, then you can just reference the CFCs by their filename and CF will find them. There's a performance hit with doing this if the directory structure is complex. That said: not much of a performance hit.

Really... you should have a mapping to the top level of your app's directory, and then use the mapping to fully-path the CFCs. That's how it's generally done, and is the most transportable approach, I think.

他のヒント

You could include the CFC from the level up in a Proxy.cfc that is at the same level as the calling CFC and then extend Proxy.cfc by adding extends="Proxy" as an attribute of the calling CFC.

Example Proxy.cfc

<cfcomponent name="Proxy">
<cfinclude template="../../service/component_to_call.cfc">
</cfcomponent>

Example calling cfc

<cfcomponent name="calling" extends="Proxy">
</cfcomponent>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top