[Tip of the Week] Decorating Your Controller

If you’ve ever wanted to modify any behavior of the core ColdBox controller, you can now do so as of version 3.5.3 with the Controller Decorator feature. This is accomplished much like the Request Context Decorator.

First, add a configuration setting called “ControllerDecorator” in the coldbox struct of your config file.

coldbox.controllerDecorator = “path.to.myControllerDecotrator”;

Next, build your decorator as a CFC that extends our base coldbox.system.web.ControllerDecorator class like so.

component extends=“coldbox.system.web.ControllerDecorator”{

function setNextEvent(){
arguments.ssl = true;
getController.setNextEvent( argumentCollection=arguments );


That example would wrap the setNextEvent method and force it to always redirect to a secure URL.

More info here: http://wiki.coldbox.org/wiki/WhatsNew:3.5.3.cfm#Controller_Decorator

P.S. Instead of extending a class with a super reference, the decorator pattern composes the original object in an invisible wrapper class which contains a reference to the original. In your controller decorator, you can use the getController() method to get the original controller object.



ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com