Pavan Reddy
Pavan Reddy

Reputation: 173

Application.cfc vs Application.cfm which has more priority in different folders

In my application root folder, I have an Application.cfc file. In a subfolder, there is an Application.cfm. When I call a script in the subfolder which Application file executes: Application.cfc or Application.cfm?

Upvotes: 2

Views: 2687

Answers (3)

axltop
axltop

Reputation: 11

Actually there are server settings which also influence the way which application.cfc/cfm file is executed. In the

Application.cfc/Application.cfm lookup order

Select the order in which ColdFusion searches for Application.cfm or >Application.cfc if it is not found in the current project folder. You can >set ColdFusion to search as follows:

  • default search order: ColdFusion looks for an >Application.cfc/Application.cfm file from the current folder until the >system root directory. On Windows, this could be C:\ and on UNIX, /opt.
  • till web root: ColdFusion looks for an Application.cfc/Application.cfm >file from the current folder till web root.
  • in web root: ColdFusion looks for an Application.cfc/Application.cfm file >in the current folder or web root.

CFIDE SETTINGS

Upvotes: 0

Vlad
Vlad

Reputation: 1167

Application.cfm gets executed and to learn more about the order of execution. From the documentation:

How ColdFusion finds and process application definition pages

ColdFusion uses the following rules to locate and process the Application.cfc, Application.cfm, and OnRequestEnd.cfm pages that define application-specific elements. The way ColdFusion locates these files helps determine how you structure an application.

Each time ColdFusion processes a page request it does the following:

  1. When ColdFusion starts processing the request, it does the following:

    • It searches the page's directory for a file named Application.cfc. If one exists, it creates a new instance of the CFC, processes the initial events, and stops searching. (ColdFusion creates a new
      instance of the CFC and processes its initialization code for each
      request.)

    • If the requested page's directory does not have an Application.cfc file, it checks the directory for an Application.cfm file. If one
      exists, ColdFusion logically includes the Application.cfm page at the beginning of the requested page and stops searching further.

    • If the requested page's directory does not have an Application.cfc or Application.cfm file, ColdFusion searches up the directory tree and checks each directory first for an Application.cfc file and then, if one is not found, for an Application.cfm page, until it reaches the root directory (such as C:). When it finds an Application.cfc or Application.cfm file, it processes the page and stops searching.

  2. ColdFusion processes the requested page's contents.
  3. When the request ends, ColdFusion does the following:
    • If you have an Application.cfc, ColdFusion processes the CFC's onRequestEnd method and releases the CFC instance.
    • If you do not have an Application.cfc, but do have an Application.cfm page, ColdFusion looks for an OnRequestEnd.cfm in the same directory as the Application.cfm page ColdFusion uses for the current page. ColdFusion does not search beyond that directory, so it does not run an OnRequestEnd.cfm page that resides in another directory. Also, the OnRequestEnd.cfm page does not run if there is an error or an exception on the application page, or if the application page executes the cfabort or cfexit tag.


The following rules determine how ColdFusion processes application pages and settings:

  • ColdFusion processes only one Application.cfc or Application.cfm page for each request. If a ColdFusion page has a cfinclude tag pointing to an additional ColdFusion page, ColdFusion does not search for an Application.cfc or Application.cfm page when it includes the additional page.

  • If a ColdFusion page has a cfapplication tag, it first processes any Application.cfc or Application.cfm, and then processes the
    cfapplication tag. The tag overrides the settings from the
    application files, including the application name and the behaviors
    set by the cfapplication tag attributes.

  • You can have multiple Application.cfc files, Application.cfm files, and cfapplication tags that use the same application name. In this
    case, all pages that have the same name share the same application
    settings and Application scope and set and get all the variables in
    this scope. ColdFusion uses the parameter settings of the
    cfapplication tag or the most recently processed file, if the
    settings, such as the session time-out, differ among the files.

Upvotes: 2

Alex Baban
Alex Baban

Reputation: 11692

When you call templates in the subfolder then the Application.cfm in the subfolder gets executed.

Upvotes: 4

Related Questions