Skip to content

Commit 2c873b1

Browse files
committed
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.
1 parent 0dcc9a0 commit 2c873b1

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

Application.cfc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ component {
1818
// create your FW/1 application:
1919
request._framework_one = new framework.one( {
2020
trace = true,
21-
base = getDirectoryFromPath( CGI.SCRIPT_NAME )
21+
missingview = 'main.missingview',
22+
base = getDirectoryFromPath( CGI.SCRIPT_NAME )
2223
.replaceFirst( getContextRoot(), '' ) & 'introduction'
2324
} );
2425

framework/one.cfc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -742,14 +742,24 @@ component {
742742
}
743743
// setup the new controller action, based on the error action:
744744
request._fw1.controllers = [ ];
745-
746-
if ( structKeyExists( variables, 'framework' ) && structKeyExists( variables.framework, 'error' ) ) {
747-
request.action = variables.framework.error;
745+
var key = 'error';
746+
var defaultAction = 'main.error';
747+
try {
748+
if ( exception.type == 'fw1.viewnotfound' && structKeyExists( variables.framework, 'missingview' ) ) {
749+
key = 'missingview';
750+
// shouldn't be needed -- key will be present in framework config
751+
defaultAction = 'main.missingview';
752+
}
753+
} catch ( any e ) {
754+
// leave it as exception
755+
}
756+
if ( structKeyExists( variables, 'framework' ) && structKeyExists( variables.framework, key ) ) {
757+
request.action = variables.framework[ key ];
748758
} else {
749759
// this is an edge case so we don't bother with subsystems etc
750760
// (because if part of the framework defaults are not present,
751761
// we'd have to do a lot of conditional logic here!)
752-
request.action = 'main.error';
762+
request.action = defaultAction;
753763
}
754764
// ensure request.context is available
755765
if ( !structKeyExists( request, 'context' ) ) {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
I'm sorry, but no such view is available!
2+
<cfdump var="#request#"/>

0 commit comments

Comments
 (0)