Jason Steinshouer

about blog projects

Executing Coldbox Events in Legacy Code

A quick tip for future Jason or anyone else who may work with Coldbox and legacy code (not MVC) running side-by-side. I found this well documented in the Coldbox Documentation but wanted to post it as a quick reference for myself.


Here the action is defined with a widget argument. When running it as a widget it will return the rendered content. Otherwise it is ran as a regular Coldbox request.

component extends="coldbox.system.EventHandler" {
	function myEvent(event,rc,prc,widget=false) {
		prc.message = "Test from Coldbox event";
		if (arguments.widget) {
			return renderView("main/myView");



Simple view that just outputs the message.



Now I call the Coldbox event from my legacy code like so.


UPDATE: 11/29/2016

I found out that since my legacy code was not running inside a Colbox request that I also needed to populate the Coldbox RequestContext so the event had access to any url or form scope parameters.

<cfset application.cbController.getRequestService().requestCapture()>