Skip to content

How do I execute a subroutine from an event filter?

thofrey edited this page Jul 23, 2013 · 2 revisions

There is no built-in API shortcut like announceEvent() to execute subroutine from within an event-filter. However, you can execute a subroutine anywhere there is access to the EventContext.

You can execute a subroutine by calling this code:

    <cffunction name="filterEvent" access="public" returntype="boolean" output="true"
        hint="Runs the filter event.">
        <cfargument name="event" type="MachII.framework.Event" required="true" />
        <cfargument name="eventContext" type="MachII.framework.EventContext" required="true" />
        <cfargument name="paramArgs" type="struct" required="true" />

        <cfset var nameOfSubroutine = "" />

        <!---
        Logic that decides the name of the subroutine to execute
        --->

        <cfset arguments.eventContext.executeSubroutine(nameOfSubroutine, arguments.event) />

        <cfreturn TRUE />
    </cffunction>

Additional Notes and Considerations

  • Be sure to set the output attribute of the method to true as subroutines can output data such if they contain <view-page> commands otherwise the output of views will be suppressed.

Back to FAQs

Clone this wiki locally