Skip to content

Commit

Permalink
framework.missingview is action for viewnotfound exception
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
seancorfield committed Nov 28, 2016
1 parent 0dcc9a0 commit 2c873b1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Application.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -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'
} );

Expand Down
18 changes: 14 additions & 4 deletions framework/one.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) ) {
Expand Down
2 changes: 2 additions & 0 deletions introduction/views/main/missingview.cfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
I'm sorry, but no such view is available!
<cfdump var="#request#"/>

0 comments on commit 2c873b1

Please sign in to comment.