how do I access eventContext from a listener?

1 view
Skip to first unread message

jarthel

unread,
Oct 29, 2009, 3:29:40 AM10/29/09
to Mach-II for CFML
In examples, I've always seen "event" being used as argument to a
function in a listener.

How do I use eventContext (just like the example in the plugin wiki
page).

Thank you

jayel

Brian FitzGerald

unread,
Oct 29, 2009, 9:36:24 AM10/29/09
to Mach-II for CFML
I've read this question and response before on the list but I couldn't
find it when I just searched the group archives. I've set up a FAQ on
the wiki which I will flesh out with the information from this thread.

I know this is not possible by design. By design, the event context
is only available to filters and plugins, and not to listeners. I
have read that the reasoning behind this is to prevent you from trying
to do to much in your listeners and causing yourself problems down the
road. Unfortunately I can't provide more detail than that because I'm
not 100% sure of the original thought behind that choice. Could what
you're trying to to do be easily accomplished in a filter or plugin
instead?

Best,
Brian




On Oct 29, 3:29 am, jarthel <jart...@gmail.com> wrote:
> In examples, I've always seen "event" being used as argument to a
> function in alistener.
>
> How do I useeventContext(just like the example in the plugin wiki
> page).
>
> Thank you
>
> jayel

Adrian Scott

unread,
Oct 29, 2009, 2:10:52 PM10/29/09
to Mach-II for CFML
I think Brian has this right, while you can interpret the Mach-II
framework as however you wish, I believe by design it's setup thusly:

Plugins
provide some logic that run on every request and have the ability to
change the flow of the event if required - best used for checks that
are needed on every page-load, such as checking login status

Filters
provide logic on a per-event basis and have access to both the event
and eventContext - best used to check request requirements on this per-
event basis and redirect the event elsewhere if required

Listeners
bridge between your View and your Model - allows the passing of event
arguments to the Service layer (if used) and obtaining any information
from the back-end that you'll want to use in a View

By the sound of things, what you're looking for is probably a Filter.
It's my opinion that Listeners should really be used sparingly and not
contain any logic in them; they should act as more of a flow through
of data.

Adrian.

jarthel

unread,
Oct 29, 2009, 7:06:34 PM10/29/09
to Mach-II for CFML
Thanks everyone. :)
Reply all
Reply to author
Forward
0 new messages