Last change
on this file since 8 was
8,
checked in by duh, 12 years ago
|
Renamed DebugController? to base controller, investigating Grails' Interceptors
|
-
Property svn:keywords set to
Date Author Rev
|
File size:
1.5 KB
|
Line | |
---|
1 | import org.codehaus.groovy.grails.commons.GrailsApplication |
---|
2 | import grails.util.GrailsUtil |
---|
3 | |
---|
4 | /** |
---|
5 | * Base Controller |
---|
6 | * @Author Jeroen Wesbeek |
---|
7 | * @Since 20091014 |
---|
8 | * @Description |
---|
9 | * |
---|
10 | * Base Controller which provides general functionality |
---|
11 | * |
---|
12 | * Revision information: |
---|
13 | * $Rev: 8 $ |
---|
14 | * $Author: duh $ |
---|
15 | * $Date: 2009-10-14 16:29:37 +0000 (wo, 14 okt 2009) $ |
---|
16 | */ |
---|
17 | class BaseController { |
---|
18 | /** |
---|
19 | * Turn scaffolding on or off |
---|
20 | */ |
---|
21 | def scaffold = (GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT && this.class.name != 'DebugController'); |
---|
22 | |
---|
23 | /** |
---|
24 | * Render default output to the browser, overload this method to suit your needs |
---|
25 | */ |
---|
26 | def index = { |
---|
27 | render(sprintf("%s @ %s environment :: nothing to see here! :)",this.class.name,GrailsUtil.environment)); |
---|
28 | } |
---|
29 | |
---|
30 | /** |
---|
31 | * intercept any method calls in extended classes |
---|
32 | * @see http://www.grails.org/Controllers+-+Interceptors |
---|
33 | */ |
---|
34 | def beforeInterceptor = [action:this.&auth,except:'login'] |
---|
35 | |
---|
36 | /** |
---|
37 | * after interception |
---|
38 | * @see http://www.grails.org/Controllers+-+Interceptors |
---|
39 | */ |
---|
40 | def afterInterceptor = { model, modelAndView -> |
---|
41 | println "Current view is ${modelAndView.viewName}" |
---|
42 | if(model.someVar) modelAndView.viewName = "/mycontroller/someotherview" |
---|
43 | println "View is now ${modelAndView.viewName}" |
---|
44 | } |
---|
45 | |
---|
46 | /** |
---|
47 | * authentication method |
---|
48 | */ |
---|
49 | def auth() { |
---|
50 | if(!session.user) { |
---|
51 | redirect(action:'login') |
---|
52 | return false |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | /** |
---|
57 | * login method |
---|
58 | */ |
---|
59 | def login = { |
---|
60 | // display login page |
---|
61 | println "render login..."; |
---|
62 | } |
---|
63 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.