Ignore:
Timestamp:
Oct 14, 2009, 6:29:37 PM (10 years ago)
Author:
duh
Message:

Renamed DebugController? to base controller, investigating Grails' Interceptors

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/BaseController.groovy

    r7 r8  
     1import org.codehaus.groovy.grails.commons.GrailsApplication
    12import grails.util.GrailsUtil
    23
    34/**
    4  * Debug Controller
     5 * Base Controller
    56 * @Author  Jeroen Wesbeek
    67 * @Since   20091014
    78 * @Description
    89 *
    9  * If all controllers extend this debug controller in one piece of code the
    10  * behaviour of the other controllers can be -to some extent- manipulated.
     10 * Base Controller which provides general functionality
    1111 *
    1212 * Revision information:
     
    1515 * $Date$
    1616 */
    17 class DebugController {
     17class BaseController {
    1818    /**
    1919     * Turn scaffolding on or off
     
    2222
    2323    /**
    24      * Render output to the browser, overload this method to suit your needs
     24     * Render default output to the browser, overload this method to suit your needs
    2525     */
    2626    def index = {
    2727        render(sprintf("%s @ %s environment :: nothing to see here! :)",this.class.name,GrailsUtil.environment));
    2828    }
     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    }
    2963}
Note: See TracChangeset for help on using the changeset viewer.