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>

