Hey Dan,

That's a great explanation. Do you mind if I add some of your post to the
FAQ section on the Wiki?


DW

On Tue, Jun 21, 2011 at 9:29 PM, Dan Skaggs <[email protected]>wrote:

> Couple of things here:
>
> 1) Passing your entire populated model object to the view (via the
> ModelGlue event object) is perfectly fine. There's no reason to break out
> all the object's properties into separate values in the event.
>
> 2) ModelGlue controllers are created once on application init (or when you
> manually reinit the app) and cached. Therefore, yes, the controller objects
> are in effect singletons for the application.
>
> 3) Instead of doing <cfset variables.item ...>, you should do <cfset var
> item = createObject(.....) />. Using variables.item actually would set the
> object into the global memory space for the controller component (which
> would be bad as that value is then cached as part of the controller
> singleton--see #2). Using the "var" keyword on a variable inside a function
> body ensures that the variable only exists for that execution of the
> function (therefore it can't be stored and bleed over into other requests
> that execute that same function). The variable is discarded after the
> function completes executing.
>
> 4) Using the var keyword has nothing to do with the user session--they are
> 2 completely different ideas.
>
> 5) There's no need to cfparam the url.uuid. ModelGlue automatically puts
> all URL and form variables into the event object for you to make it easy for
> you to find them. You just need to get the value out of the event when you
> need it (see below). Should uuid not exist in the event, ModelGlue will
> return you an empty string. You can optionally set a default value to use in
> case the variable doesn't exist in the event (see
> http://docs.model-glue.com/wiki/ReferenceMaterials/EventApi#GetValuename:stringdefault:anyfor
>  more information).
>
> Try updating your controller component as such:
>
> <cfcomponent output="false"
> extends="ModelGlue.gesture.controller.Controller">
>
> <cffunction name="view" access="public">
>        <cfargument name="event" />
>
>         <cfset var uuid = arguments.event.getValue( "uuid" ) />
>        <cfset var item = CreateObject("component", "model.item") />
>        <cfset var status = "" />
>
>        <cfinvoke component="#item#"
>                method = "get"
>                returnvariable = "status"
>                 uuid = "#uuid#"
>                >
>
>       <cfset arguments.event.setValue("item", item) />
>
> </cffunction>
> </cfcomponent>
>
> Additionally, while there's nothing wrong technically with using a
> <cfinvoke> there, you could shorten that up like so:
>
> <cffunction name="view" access="public">
>        <cfargument name="event" />
>
>         <cfset var item = CreateObject("component", "model.item") />
>
>        <cfset item.get( uuid = arguments.event.getValue( "uuid" ) ) />
>
>       <cfset arguments.event.setValue("item", item) />
>
> </cffunction>
> </cfcomponent>
>
> Hope that helps clarify things a bit. If there's something you don't
> understand, be sure to ping us back.
>
> Dan
>
> On Jun 21, 2011, at 8:09 PM, Brettski wrote:
>
> > And should I scope like
> >
> > <cfset Variables.item = CreateObject("component", "model.item")>
> > ..
> > <cfset arguments.event.setValue("item", Variables.myItem) />
> >
> >
> > On Jun 22, 11:01 am, Brettski <[email protected]> wrote:
> >> the model bits and pieces are all used in the view, am I thinking
> >> wrong to pass all this back to view? What else should I pass back a
> >> struct or something?
> >>
> >> My vars aren't scoped, so does this mean there is one controller
> >> "instance / singleton" for the app, and if I don't scope them they can
> >> bleed? I think that's if I scope all vars they will stay in user
> >> session?
> >>
> >> On Jun 22, 9:55 am, Roy Martin <[email protected]> wrote:
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>> Off the cuff, you haven't var scoped your 'item' variable or your
> return
> >>> variable 'status'. So those variable will be subject to variable bleed
> under
> >>> load. As an additional point of feedback, passing the entire model back
> to
> >>> the view isn't best practice. It would be better if you had passed just
> the
> >>> return variable back to the model. Unless that's a typo?
> >>
> >>> Thanks,
> >>> Roy
> >
> > --
> > 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
>
> --
> 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
>



-- 
Plutarch - "The mind is not a vessel to be filled but a fire to be kindled."

-- 
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

Reply via email to