Title: RE: Page context bug workaround (was RE: [CFCDev] MVCF at benorama.com)
Interesting approach Benoit.  For the sake of discussion, it might be worth talking about a solution with less overhead than CF_REINIT ....
 
In the constructor, you might do something like:
 
<cfscript>
instance.application = application;
instance.session = session;
</cfscript>
 
You can then refer to instance.application.foo in the code of your methods, and you will end up with the right variables.  This works because you are creating a reference in the private scope to the Application/Session -- since you do it on instantiation, the reference "sticks" to the "right" Application/Session.  Since it's only a reference it uses minimal memory, and isn't even that ugly (thus, won't necessarily require code changes later).  You incur much less overhead from what I can tell than the cf_reinit that you sent, which seems a bit heavy to have to run on every request (and inside your CFCs every time you want to use those vars).
 
Another option, of course, is to just pass the Application and/or Session in as an argument when running your init() method (assuming you do that kind of thing).  I've done this at times using the ARGUMENTCOLLECTION -- I then only grab the private instance vars that I need -- this is a little messy in that it would assume you know the names of the application vars you want, but it does a nicer job, IMO, of maintaining encapsulation than "raw" reference to the Application scope.
 
I've also experimented with having a component instance called "globals" which stores a struct internally and storing that in the Application scope -- I then pass that when initializing components I want to store in the Application scope and inside can do something like:
 
instance.globals.getVar("dsn")
 
That's a bit of a heavy solution, but it is better at maintaining encapsulation while still having non-specific "global" variables that can be cached in the application scope.
 
 - Nathan
 
 
 
 
 
 
 
 
 
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of Benoit Hediard
Sent: Tuesday, March 25, 2003 12:21 PM
To: [EMAIL PROTECTED]
Subject: RE: Page context bug workaround (was RE: [CFCDev] MVCF at benoram a.com)

Oops sorry, I didn't know that this mailing list accept attachments.
 
Here it is attached.
It was developed by Paul Kenney.
 
To use it is pretty simple :
- in your Application.cfm, put <cf_reinit method="Initialize">,
- in each one of the methods of the Session CFC where you need to get back the page context, put <cf_reinit pageContext="#getPageContext()#">.
 
Benoit Hediard
www.benorama.com
-----Message d'origine-----
De : [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]De la part de Davis, Eric
Envoy� : mardi 25 mars 2003 20:47
� : '[EMAIL PROTECTED]'
Objet : RE: Page context bug workaround (was RE: [CFCDev] MVCF at benoram a.com)

Heck, Benoit, why not just post it to the list?

--
Eric C. Davis
Programmer/Analyst I
Georgia Department of Transportation
Office of I.T. Applications
Web Applications Group
404.463.2860.158
[EMAIL PROTECTED]

Reply via email to