The link from Lola goes to a great Doug Boude article, and he does a good
job of describing MVC.
Just to supplement, I will show you some snippets of MG from the QuickStart.
The simplicity and the three aspects of MVC should be apparent. Bear in mind
that the purpose of MVC is to eliminate spagetti code by keeping code
separated into 3 different buckets. Bucket 1 is the *view* and it's the
place (folder) where templates (and objects) go that render things onto the
display. The *controller* listens to requests from the *view *and sends
them to the *model *for processing and then catches things being sent back
from the *model* and fields them back to the *view*... it's like a middle
layer traffic cop, directing things. The real work horse is the *model*. It
holds all the objects that do little jobs by exposing their methods in the *
controller* by dependency injection.
*
MG (QuickStart - a subset)
**The event object *(invisible) gets a request for: *translationForm* and
looks for an event handler in *ModelGlue.xml* that matches:
<event-handler name="translationForm" type="templatedPage">
<views>
<include name="body" template="frmPhrase.cfm">
<value name="xe_translate" value="translationFormAction" />
</include>
</views>
</event-handler>
frmPhrase.cfm in *view *makes this form request upon submission using the
form action:* translationFormAction*
The *event object *intercepts the request and looks in *ModelGlue.xml* for
an event handler that matches the request
*it finds this:*
<event-handler name="translationFormAction" type="templatedPage">
*As you can see, this handler immediately triggers a broadcast which needs
to be attended to in the controller section of ModelGlue.xml
* <broadcasts>
<message name="NeedTranslation" />
</broadcasts>
*So we jump up to this controller section *(I moved some code down here to
show it to you)* and there we see a controller item setup to listen for this
exact message. It also requests the invocation of the TranslatePhrase
method, inside the controller. (Controller.cfc)*
<controllers>
<controller id="Controller" type="translator.controller.Controller">
<message-listener message="NeedTranslation"
function="TranslatePhrase" />
</controller>
</controllers>
*We don't know how long we'll be gone, or what all we'll have to do, way out
there in Controller land... but we do know that when we're done, we'll come
right back down here to finish what we started in this view.*
<views>
<include name="body" template="dspPhrase.cfm">
<value name="xe_translationForm" value="translationForm" />
</include>
</views>
<results>
<result name="ValidationError" do="translationForm" redirect="true"
/>
</results>
</event-handler>*
*
Notice how this *Controller.cfc* (below) calls (creates) *
PigLatinTranslator.cfc* in the *model* folder, and instantiates it (init)
with "aeiou" ?
This means that the object *PigLatinTranslator *is now "present and
accounted for" to quote *Doug Boude* and "ready for duty"
(to quote myself...)
Then the next line gets the phrase it stored in the *event object* (from the
form) and stores it in the *internal* (protected) var *phrase*...
Once the phrase is stored in "*phrase*" it's sent into (*injected*) into the
*translate *method of the *translator object *in the *model*.
There, it's translated into Pig Latin and the value is returned to us and
stored in the internal var *result*.
Finally, the last two lines of code are processed here in the controller to
finish off the *TranslatePhrase *method.
1. <cffunction name="TranslatePhrase" access="public" returntype="void"
output="false">
2. <cfargument name="event" type="any">
3.
4. *<cfset var translator = createObject("component",
"translator.model.PigLatinTranslator").init("aeiou") />** *
5. *<cfset var phrase = arguments.event.getValue("phrase") /> *
6. * <cfset var result = translator.translate(phrase) /> *
7.
8. <cfset arguments.event.addTraceStatement("User",
"TranslatePhrase Results", result) />
9. <cfset arguments.event.setValue("translatedPhrase", result) />
10. </cffunction>
Isn't it cool how we just made the *model *do work for us while we were
still sitting in the *controller *? I believe that's called* Inversion of
Control *for all those people out there that like to drop buzz words during
an interview...
But the real cool thing is that now we just click our heels together and
keep repeating: "there's no place like home" and before you can say
Model-Glue, we are whisked back to the middle of the event-handler from
which we came, and we resume calling up the view that displays our results.
<views>
<include name="body" template="dspPhrase.cfm">
<value name="xe_translationForm" value="translationForm" />
</include>
</views>
<results>
<result name="ValidationError" do="translationForm" redirect="true"
/>
</results>
</event-handler>* *
Now wasn't that fun, and quite painless !
On Thu, Jul 29, 2010 at 6:04 PM, Lola Lee Beno <[email protected]> wrote:
> On 7/29/10 9:00 PM, Rich wrote:
>
> Does anyone have a good resource (url, preso, book, etc.) about explaining
> the basics of MVC, in particular to how it's applied when using MG? If
> there's something right in front of my nose I apologize in advance.
>
> Keep up the good work, your efforts are NOT going unnoticed....
>
> Rich
>
>
> Doug Boude had a couple of really good posts explaining what goes on with
> MG. Here's the category list:
>
>
> http://www.dougboude.com/blog/index.cfm?mode=cat&category_id=DEA32F54-963A-DAC1-0D602FC5FF563F7F
>
> --
> Lola J. Lee Beno
> LinkedIn: http://www.linkedin.com/in/lolajleebeno
> Facebook: http://www.facebook.com/profile.php?id=714355583
> Blog: http://www.lolajl.net/blog/
>
> --
> 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]<model-glue%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/model-glue?hl=en
>
--
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