Application Specific Mapping Workaround - Mach-II/Mach-II-Framework GitHub Wiki

Overview

This does not affect BlueDragon users as application specific mappings via <cfmapping ... /> work as expected.

This FAQ is for Adobe ColdFusion 8+.

Application specific mappings do not work on Adobe ColdFusion 8 when extending your Application.cfc with MachII.mach-ii as application specific mappings are set after your Application.cfc is instantiated. This causes ColdFusion to throw an error saying it cannot find the MachII.mach-ii CFC.

Common Error

Could not find the ColdFusion Component or Interface MachII.mach-ii. Ensure that the name is correct and that the component or interface exists.

This occurs because application specific mappings are only available after the psuedo-constructor area is run (the part outside of any functions; usually at the top of a CFC right below the cfcomponent tag).

Your Application.cfc needs to inherit (i.e. <cfcomponent extends="MachII.mach-ii">) from the MachII.mach-ii CFC, this will fail because Adobe ColdFusion does not know where that CFC and because inheritance is processed before the pseudo-constructor area. This introduces us into a catch-22 situation.

Workarounds

The simplest workarounds in the order of ease are:

  1. Place the Mach-II framework in your web root of your website
  2. Use a server-wide mapping set in the ColdFusion Administrator
  3. However if this none of these options are not available to you, next workaround is to copy the mach-ii.cfc into the same directory as your Application.cfc and set application specific mapping in your Application.cfc. This works because application specific mappings are available after the pseudo-constructor is executed and ColdFusion has begun process application events (i.e. onApplicationStart, onRequestStart, etc.).

Instructions to Workaround 3

  1. Copy the mach-ii.cfc file from the Mach-II core to the same directory as your Application.cfc.
  2. Put extends="mach-ii" into the <cfcomponent> tag of your Application.cfc.
  3. Set an application specific mapping named MachII in your Application.cfc. We recommend using a relative path instead of an absolute path instead this reduces the dependency of having your environment setup the same on each server that you deploy your application.

Example Application.cfc (note that this extends mach-ii CFC which you copied into the same directory as your Application.cfc thus no mapping is required at for inheritence):

    <cfcomponent name="Application.cfc" extends="mach-ii" output="false">

        <!---
        PROPERTIES - APPLICATION SPECIFIC
        --->
        <cfset this.name = "YourApplication" />
        <cfset this.applicationTimeout = CreateTimeSpan(30,0,0,0) />
        <cfset this.mappings["/MachII"] = "[drive]/path/to/MachII" />
        ...More application specific attributes...

        <!---
        PROPERTIES - MACH-II SPECIFIC
        --->

        <!--- Set the path to the application's mach-ii.xml file --->
        <cfset MACHII_CONFIG_PATH = ExpandPath("/path/to/config/mach-ii.xml") />

        <!--- Set the app key for sub-applications within a single cf-application. --->
        <cfset MACHII_APP_KEY = "YourApplication" />

        <!--- Set the configuration mode (when to reload): -1=never, 0=dynamic, 1=always --->
        <cfset MACHII_CONFIG_MODE = -1 />

        <!---
        onApplicationStart() and onRequestStart() methods are inherited and do not need
        to be defined unless customized functionality is required
        --->
    </cfcomponent>