From 2c873b15a3c311e202626b75c75a504abce6aa90 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Sun, 27 Nov 2016 16:36:06 -0800 Subject: [PATCH] framework.missingview is action for viewnotfound exception This is backward compatible, opt-in behavior. Add `missingview : 'some.action'` to your framework config and that action will be taken instead of what is specified by `error` in that config. --- Application.cfc | 3 ++- framework/one.cfc | 18 ++++++++++++++---- introduction/views/main/missingview.cfm | 2 ++ 3 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 introduction/views/main/missingview.cfm diff --git a/Application.cfc b/Application.cfc index efa4ba9e..149e6b60 100644 --- a/Application.cfc +++ b/Application.cfc @@ -18,7 +18,8 @@ component { // create your FW/1 application: request._framework_one = new framework.one( { trace = true, - base = getDirectoryFromPath( CGI.SCRIPT_NAME ) + missingview = 'main.missingview', + base = getDirectoryFromPath( CGI.SCRIPT_NAME ) .replaceFirst( getContextRoot(), '' ) & 'introduction' } ); diff --git a/framework/one.cfc b/framework/one.cfc index 73fa7618..0cee02ee 100644 --- a/framework/one.cfc +++ b/framework/one.cfc @@ -742,14 +742,24 @@ component { } // setup the new controller action, based on the error action: request._fw1.controllers = [ ]; - - if ( structKeyExists( variables, 'framework' ) && structKeyExists( variables.framework, 'error' ) ) { - request.action = variables.framework.error; + var key = 'error'; + var defaultAction = 'main.error'; + try { + if ( exception.type == 'fw1.viewnotfound' && structKeyExists( variables.framework, 'missingview' ) ) { + key = 'missingview'; + // shouldn't be needed -- key will be present in framework config + defaultAction = 'main.missingview'; + } + } catch ( any e ) { + // leave it as exception + } + if ( structKeyExists( variables, 'framework' ) && structKeyExists( variables.framework, key ) ) { + request.action = variables.framework[ key ]; } else { // this is an edge case so we don't bother with subsystems etc // (because if part of the framework defaults are not present, // we'd have to do a lot of conditional logic here!) - request.action = 'main.error'; + request.action = defaultAction; } // ensure request.context is available if ( !structKeyExists( request, 'context' ) ) { diff --git a/introduction/views/main/missingview.cfm b/introduction/views/main/missingview.cfm new file mode 100644 index 00000000..5aa6fdd5 --- /dev/null +++ b/introduction/views/main/missingview.cfm @@ -0,0 +1,2 @@ +I'm sorry, but no such view is available! +