Highlighted

onMissingTemplate function in Application.cfc

LEGEND ,
Nov 12, 2015

Copy link to clipboard

Copied

Hello, all,

I'm trying to implement a process for missing templates, so that the user will never see a CF error message for missing pages.

The problem is that even though it will trigger my onError function, it's still outputting CF errors at the bottom of the page.

Here is my onMissingTemplate() function:

<cffunction name="onMissingTemplate" returntype="boolean" output="false" >

    <cfargument name="template" type="string" required="true" />

    <cfset this.onRequestStart(arguments.template) />

    <cfset this.onRequest(arguments.template) />

    <cfreturn true />

</cffunction>

How can I get this to stop processing after displaying the onError page, so that it won't show the CF error mesages?

V/r,

^_^

From what I can tell, your onMissingTemplate trap is probably working but your code within the event is retriggering the same error. I'm not sure your goal. I usually create an error.cfm template and simply include that module:

<cffunction name="onMissingTemplate" returntype="boolean" output="false" >

    <cfargument name="template" type="string" required="true" />

    <cfinclude template="error.cfm" />

    <cfabort />

</cffunction>

I'm not 100% certain if the cfabort call is required but it does not seem to hurt. <cfreturn false /> probably does the same thing.

Views

333

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

onMissingTemplate function in Application.cfc

LEGEND ,
Nov 12, 2015

Copy link to clipboard

Copied

Hello, all,

I'm trying to implement a process for missing templates, so that the user will never see a CF error message for missing pages.

The problem is that even though it will trigger my onError function, it's still outputting CF errors at the bottom of the page.

Here is my onMissingTemplate() function:

<cffunction name="onMissingTemplate" returntype="boolean" output="false" >

    <cfargument name="template" type="string" required="true" />

    <cfset this.onRequestStart(arguments.template) />

    <cfset this.onRequest(arguments.template) />

    <cfreturn true />

</cffunction>

How can I get this to stop processing after displaying the onError page, so that it won't show the CF error mesages?

V/r,

^_^

From what I can tell, your onMissingTemplate trap is probably working but your code within the event is retriggering the same error. I'm not sure your goal. I usually create an error.cfm template and simply include that module:

<cffunction name="onMissingTemplate" returntype="boolean" output="false" >

    <cfargument name="template" type="string" required="true" />

    <cfinclude template="error.cfm" />

    <cfabort />

</cffunction>

I'm not 100% certain if the cfabort call is required but it does not seem to hurt. <cfreturn false /> probably does the same thing.

Views

334

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 12, 2015 0
LEGEND ,
Nov 16, 2015

Copy link to clipboard

Copied

I'll add a screencap of what I'm referring to.  Everything below the logo should not be displaying.

CF_missing_template_display.gif

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 16, 2015 0
Most Valuable Participant ,
Nov 27, 2015

Copy link to clipboard

Copied

WolfShade‌, what is in your onRequest() method?  If you pass the nonexistent template as an argument of onRequest(), but don't force navigation to a different page, it would still throw an error.  Do you have a FileExists() check in onRequest() to verify the template exists prior to including it?

-Carl V.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 27, 2015 0
LEGEND ,
Nov 30, 2015

Copy link to clipboard

Copied

Hi, Carl Von Stetten‌!

My onRequest() method is bare-bones:

<cffunction name="onRequest" returntype="void">

  <cfargument name="thePage" type="string" required="true" />

  <cfinclude template="#arguments.thePage#" />

</cffunction>

The onError() method is triggered, which redirects to my errors.cfm page, and it _should_ stop processing after displaying errors.cfm.

I've seen several examples online for onRequest() and onError(), and I've never seen one include a FileExists() conditional.  Is that common??

V/r,

^_^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 30, 2015 0
Advocate ,
Nov 30, 2015

Copy link to clipboard

Copied

From what I can tell, your onMissingTemplate trap is probably working but your code within the event is retriggering the same error. I'm not sure your goal. I usually create an error.cfm template and simply include that module:

<cffunction name="onMissingTemplate" returntype="boolean" output="false" >

    <cfargument name="template" type="string" required="true" />

    <cfinclude template="error.cfm" />

    <cfabort />

</cffunction>

I'm not 100% certain if the cfabort call is required but it does not seem to hurt. <cfreturn false /> probably does the same thing.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 30, 2015 1
LEGEND ,
Nov 30, 2015

Copy link to clipboard

Copied

<cfreturn false /> did not prevent the CF error message from appearing, but <cfabort> did.  I'm a bit leery to use <cfabort>, because I don't know if that will prevent other things from happening; however, at this point, I'm willing to give it a shot in production.

Thanks, Steve Sommers‌!

V/r,

^_^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 30, 2015 0
Advocate ,
Nov 30, 2015

Copy link to clipboard

Copied

I try to limit my use of cfabort but for something like this I would use it (obviously since that was my example). If you have an onRequestEnd (or whatever it's named), cfabort does prevent it from being called. I found this out the hard way when my onRequestStart was allocating some memory and my onRequestEnd was releasing it -- upon several cfabort calls, I was out of memory and this was a tricky one to find.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 30, 2015 0