Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling CFC's on another folder level

Tags:

coldfusion

cfc

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?

like image 737
David Brierton Avatar asked Feb 08 '23 02:02

David Brierton


1 Answers

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):

  • ./my/custom/Dashboard.cfc
  • /my/custom/Dashboard.cfc
  • any/custom/tag/path/my/custom/Dashboard.cfc

Going "up" is not possible.

like image 118
Tomalak Avatar answered Feb 26 '23 20:02

Tomalak