Blog   About   Contact

ColdBox RELOAD FRAMEWORK LINK on error

I work a lot with Lightwire using ColdBox's IOC Plugin.
Sometimes I forget to reload the framework (?fwreinit=1) after adding a new method to a manager/service.
ColdBox/ColdFusion throws an error on calling the new method, because it doesn't exist in the cached cfc.

I got tired of typing ?fwreinit=1, so I adjusted ColdBox's custom error template ( {YOUR_APP}/includes/generic_error.cfm )
and added a reload framework link. Simple, but a time saver...

You don't want to show a reload link on live systems, so I integrated the environment variable.
This variable is set by the evironment interceptor or by the config settings tag: DevEnvironments.

STEP 1:
Make sure you have a valid value for 'CustomErrorTemplate' in your ColdBox settings file.
e.g. includes/generic_error.cfm

STEP 2:
Skip if you're using the environment interceptor.

Make sure that you have setup your DevEnvironments settings tag e.g.
<DevEnvironments>
     <url>localhost</url>
</DevEnvironments>

STEP 3:
Copy/REPLACE the following code in the error template (includes/generic_error.cfm).


<cfset exception = event.getValue("ExceptionBean")>

<!--- Which environment? Show reload framework link? --->
<cfswitch expression="#controller.getSetting('environment')#">
    <cfcase value="development">
        <cfset fwReInitHref = "#CGI.SCRIPT_NAME#?#CGI.QUERY_STRING#">
        <cfif not REFindNoCase('fwreinit',CGI.QUERY_STRING)>
            <cfset fwReInitHref = fwReInitHref & '&fwreinit=1'>
        </cfif>
        <cfoutput>
            <div align="center"><a href="#fwReInitHref#" style="color:blue;">Reload framework</a></div>
        </cfoutput>
        <!--- Default ColdBox error template --->
        <cfinclude template="/coldbox/system/includes/BugReport.cfm">
    </cfcase>
    <cfdefaultcase>
        <!--- Error message on live environment --->
        Sorry, an error occured, please contact administrator    
    </cfdefaultcase>
</cfswitch>

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Tony Garcia's Gravatar In ColdBox 2.6 there is also a "Reinitialize Framework" button in the Debugging panel (of course, it's only relevant if you have debugging turned on.)
# Posted By Tony Garcia | 7/28/08 7:47 PM
Ernst van der Linden's Gravatar Tony I know, but I almost never use CB's debug panel.
# Posted By Ernst van der Linden | 7/28/08 8:06 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.004.