Time for yet another quick Model-Glue 3 example. This time I wanted to show off formats. In the past, if you wanted to have multiple views of the same type of data, you had to build multiple events. So for example, one page may display a list of all the starships in your fleet in HTML format. If you wanted the same query in JSON, then you would build another event to handle that request. Model-Glue 3 makes this a heck of a lot simpler. The views XML entity now supports a format attribute. So for example:
2 <include name="body" template="starships.json.cfm">
3 </views>
4 <views>
5 <include name="body" template="starships.cfm">
6 </views>
2 <views format="iphone">
3 <include name="body" template="templates/iphone.cfm" />
4 </views>
5 <views>
6 <include name="main" template="templates/main.cfm" />
7 </views>
8 </event-handler>
2 <cfargument name="event" type="any" required="true">
3
4 <cfif findNoCase("iphone", cgi.http_user_agent) or findNoCase("ipod", cgi.http_user_agent) or arguments.event.valueExists("ray")>
5 <cfset arguments.event.setValue("requestformat", "iphone")>
6 </cfif>
7 </cffunction>
Comment 1 written by Shimju David on 14 May 2008, at 11:46 AM
Comment 2 written by RyanTJ on 14 May 2008, at 4:20 PM
Comment 3 written by Raymond Camden on 14 May 2008, at 4:26 PM
Comment 4 written by Jon Clausen on 15 May 2008, at 12:06 AM
It seems to me that this would allow you to organize and define those elements without having to create separate event-handlers for each request - or (just thinking out loud) create a single ajax event-handler and and incorporate use the "format" attribute in lieu of case statements to serve the request data or HTML.
Thanks for the example! I'm going to have to upgrade my MG apps to MG3 and play. So much code - so little time :)
Comment 5 written by Dominic Watson on 15 May 2008, at 12:32 PM