Why not do the parsing and processing in the page.missing event? Then you dont need to squash it.
Sean On Nov 7, 3:41 pm, Chris Blackwell <[email protected]> wrote: > NB. what follows is not meant to be a serious piece of code, i was bored and > well you know the saying "the devil makes work for idle hands" :) > > Jared, please stop reading now... > > I was wondering if there was anything to these frameworks that do everything > by convention, you know executing a controller method and including a view > template simply by parsing out the ?event=foo.bar url parameter. Then i > thought, hey ModelGlue can do that too, that's the beauty of configuration, > its you know.. configurable! > > So, i thought use MG's onRequestStart message, grab the event=foo.bar, see > if theres a matching controller and method, if so execute it. Then see if > foo/bar.cfm exists in a view mapping and if so render it. simples no? > > Turns out MG wants to queue up the page.missing event-handler even though > you've manually queued an event, so you need to run your code onRequestEnd > so it squashes the previous output, there's probably a way round that but i > didn't spend too much time looking. > > here's some code... > > In MG.xml > <controller id="ConventionController" > type="controller.ConventionController"> > <message-listener message="onRequestEnd" function="dispatchEvent" /> > <message-listener message="onRequestEnd" function="renderView" /> > </controller> > <controller id="test" type="controller.TestController" /> > > in ConventionController.cfc > > <cffunction name="dispatchEvent" output="false" access="public" > returntype="void"> > <cfargument name="event" /> > <cfset var ev = event.getValue(event.getValue("eventValue")) /> > <cfset var ct = "" /> > <cfset var fn = "" /> > <cfset var ctrls = "" /> > <cfif listlen(ev, ".") IS 2> > <cfset ct = listfirst(ev, ".") /> > <cfset fn = listlast(ev, ".") /> > <cfset ctrls = event.getModelGlue().controllers /> > <cfif structKeyExists(ctrls, ct) AND structKeyExists(ctrls[ct], fn) AND > isCustomFunction(ctrls[ct][fn])> > <cfinvoke component="#ctrls[ct]#" method="#fn#"> > <cfinvokeargument name="event" value="#event#" /> > </cfinvoke> > </cfif> > </cfif> > </cffunction> > > <cffunction name="renderView" output="false" access="public" > returntype="void"> > <cfargument name="event" /> > <cfset var ev = event.getValue(event.getValue("eventValue")) /> > <cfset var ct = "" /> > <cfset var fn = "" /> > <cfset var views = event.getModelGlue().configuration.viewmappings /> > <cfset var i = "" /> > <cfset var view = "" /> > <cfset var handler = "" /> > <cfset var result = "" /> > > <cfif listlen(ev, ".") IS 2> > <cfset ct = listfirst(ev, ".") /> > <cfset fn = listlast(ev, ".") /> > <cfloop array="#views#" index="i"> > <cfif fileExists(expandpath("#i#/#ct#/#fn#.cfm"))> > <cfset view = createobject("component", > "ModelGlue.gesture.eventhandler.View") /> > <cfset view.name = "body" /> > <cfset view.template = "#ct#/#fn#.cfm" /> > <cfset handler = createobject("component", > "ModelGlue.gesture.eventhandler.EventHandler") /> > <cfset handler.name = ev /> > <cfset handler.addView(view) /> > <cfset result = createobject("component", > "ModelGlue.gesture.eventhandler.Result") /> > <cfset result.event = "template.main" /> > <cfset handler.addResult(result) /> > <cfset event.addTraceStatement("Convention", "Added event-handler #ev# by > convention")> > <cfset event.executeEventHandler(handler)/> > </cfif> > </cfloop> > </cfif> > </cffunction> > > Now i can call index.cfm?event=test.index and it will look for a method > called index in the test controller, if its found it'll execute it. Then > look for test/index.cfm in the registered view mappings and if it exists, > render it. > > Its good, in a really really bad way :D > Please please don't take this code and use it for anything, think of the > children! > > Chris --~--~---------~--~----~------------~-------~--~----~ Model-Glue Sites: Home Page: http://www.model-glue.com Documentation: http://docs.model-glue.com Bug Tracker: http://bugs.model-glue.com Blog: http://www.model-glue.com/blog You received this message because you are subscribed to the Google Groups "model-glue" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/model-glue?hl=en -~----------~----~----~----~------~----~------~--~---
