coldfusioncfc

Calling CFC's on another folder level


I have a page that I use cfc's on. Like this:

<cfset cfcDashboard = new dashboard()>
<cfset grab_image = cfcdashboard.getPicture()>

How do I call the cfc's if they are inside of a folder? As of right now they only work if they are on the same level or inside the same folder? How do you call a cfc that is on a different level?

Or am I not understanding the purpose of the cfc?


Solution

  • The new keyword is syntactic sugar for this call:

    <cfset cfcDashboard = createObject("component", "Dashboard")>
    

    The rules how ColdFusion resolves CFC names are in the docs.

    If you use a cfinvoke or cfobject tag, or the CreateObject function, to access the CFC from a CFML page, ColdFusion searches directories in the following order:

    1. Local directory of the calling CFML page
    2. Web root
    3. Directories specified on the Custom Tag Paths page of ColdFusion Administrator

    You can use dot notation that corresponds to any of the defined search paths.

    <cfset myDashboard = createObject("component", "my.custom.Dashboard")>
    <cfset myDashboard = new my.custom.Dashboard()>
    

    Will find (where . means the current template directory and / means the web root):

    Going "up" is not possible.