Thanks Alan.  I do see what you are saying and will make the overall
adjustments.  My thought now is slightly different.  The application.cfc
has changed to this:


<cfcomponent displayname="Application" output="true" hint="Handle the
application.">

 <!--- Set up the application. --->
 <cfset THIS.Name = "Scanner2" />
 <cfset THIS.SessionManagement = true />
 <cfset THIS.SetClientCookies = false />


 <cffunction name="OnApplicationStart" access="public" returntype="boolean"
output="false" hint="Fires when the application is first created.">
  <!--- Initialize the object --->
  <cfset application.Scanner = createObject("component", "Scanner").init()
/>
  <!--- Return out. --->
  <cfreturn true />
 </cffunction>

 <cffunction name="OnRequest" access="public" returntype="void"
output="true" hint="Fires after pre page processing is complete.">
  <cfargument name="TargetPage" type="string" required="true" />

  <cfinclude template="#TargetPage#">
 </cffunction>

 <cffunction name="OnRequestEnd" access="public" returntype="void"
output="true" hint="Fires after the page processing is complete.">
  <cfset application.Scanner.LoadPage() />
  <cfdump var="#request#">
  <!--- Return out. --->
  <cfreturn />
 </cffunction>
</cfcomponent>
The concept here is that the OnRequest would just load the actual file
(index.cfm) into the buffer.  Then in the OnRequestEnd, I would take the
buffer and load it into a variable (Request.MainPage) and then call the
LoadPage function which would be loading the design page.  The design page
would then just output the Request.MainPage when it was ready.  Below is
the new CFC.  You can see where i am trying to load the page content into
the variable.  When I output the new variable, I get nothing.  If I just
output the page content with this
(<cfoutput>#getPageContext().getOut().getString()#</cfoutput>) at any
point, it will work.  It just seems strange it isn't loading it into the
variable.  The advantage I see here is that I can control when the page
design is called or if it is called.  I can just load the main page with
the include into the variable instead.....Thoughts?


<cfcomponent output="false" name="Scannner1">
 <!--- This function initializes the SiteScan object setting up the main
variables and properties --->
 <cffunction name="init" access="public" output="false" hint="constructor">
  <cfreturn this />
 </cffunction>

 <!--- This is a helper function that will actually load a template file
into a variable. --->
 <cffunction name="LoadTemplate" access="private" output="true" >
  <cfargument name="VariableName" type="string" required="true">
  <cfargument name="TemplateFile" type="string" required="true">

  <!--- Load the template file into the variable --->
  <!--- NOTE: Keep these all on one line to reduce whitespace and extra
carriage returns at the top of your file --->
  <cfsavecontent variable="#VariableName#"><CFINCLUDE
TEMPLATE="#TemplateFile#"></cfsavecontent>
 </cffunction>

 <!--- This function is called after setting whatever global variables
(i.e. secruity) that you want --->
 <cffunction name="LoadPage" access="public" output="true">
  <!--- Load the main file in the buffer to a variable to be used in the
pagedesign file --->
  <cfsavecontent
variable="Request.MainPage"><cfoutput>#getPageContext().getOut().getString()#</cfoutput></cfsavecontent>
  <!--- Reset the buffer --->
  <cfset getPageContext().getOut().clearBuffer()>
  <cfoutput>#Request.MainPage#</cfoutput>
  <cfabort>

  <!--- Get the design file.  This can then include all of the above
variables --->
  <!--- <cfset LoadTemplate('Request.Scanner_Body','pagedesign.cfm')> --->
  <!--- <cfoutput>#Request.Scanner_Body#</cfoutput><cfset
Request.Scanner_Body = ''> --->
 </cffunction>
</cfcomponent>


On Thu, Apr 5, 2012 at 4:23 PM, Alan Holden <[email protected]> wrote:

>  I don't know how much of your code has changed since that zipped version
> you posted, so I'm going to generalize here: Try to encapsulate your
> functions. Do not let them "reach outside" into other scopes to get or put
> values.
>
> Consider each function as a sealed box, in which everything it needs MUST
> arrive via a cfargument parameter, everything it computes within MUST be
> done with locally varred values; and finally everything it produces MUST be
> transmitted out via a cfreturn.
>
> This may be vague, and may bump heads directly with the framework you had
> in mind, sorry.
>
> Alan Holden
> (at work)
>
>
> On 4/5/2012 2:53 PM, Benjamin Davis wrote:
>
> Nope.  It shows that the variable is created, but it doesn't contain any
> data.
>
>
> On Thu, Apr 5, 2012 at 3:37 PM, Alan Holden <[email protected]> wrote:
>
>>  How are you looking? - if you cfdump Request.MainPage and cfabort -
>> while INSIDE that function then do you see something?
>>
>> Alan Holden
>> (at work)
>>
>>
>> On 4/5/2012 12:24 PM, Benjamin Davis wrote:
>>
>> Ok.  That explains pretty much what I am seeing because of the way this
>> thing is working.  I think that I've come up with a good work around which
>> should solve this and still be very simple, but now I have another problem!
>>  :)
>>
>>  What I was thinking was letting the index.cfm page into the buffer,
>> then storing the buffer into a variable, reset the buffer and the load the
>> design page.  The problem that I have is that the buffer won't load into a
>> variable.  Here is what I've tried.
>>
>>  <cfset Request.MainPage = getPageContext().getOut().getString()>
>> <cfsavecontent
>> variable="Request.MainPage"><cfoutput>#getPageContext().getOut().getString()#</cfoutput></cfsavecontent>
>>
>>  Neither one of these work.  It just turns out as am empty string, but
>> if I just do <cfoutput>#getPageContext().getOut().getString()#</cfoutput> I
>> get the output. Strange....
>>
>>
>> On Thu, Apr 5, 2012 at 1:14 PM, Alex Skinner <[email protected]> wrote:
>>
>>> Cfset inside a function is not varred unless you put var in front.
>>>
>>> Variables with no scope infront and no var are local to the Cfc or
>>> template but bear in mind if you persist a Cfc or udf in a shared scope
>>> like application or session the data may persist across requests or in your
>>> case pages
>>>
>>> Alex
>>>
>>>
>>> On Thursday, 5 April 2012, Benjamin Davis <[email protected]>
>>> wrote:
>>> > I was thinking that by default <cfset> inside of a function is
>>> considered a <cfset var>.  I am incorrect on this?  If not, does that mean
>>> that every <cfset> that I do on a single page (outside of a function)
>>> should also be var'd?
>>> >
>>> > On Thu, Apr 5, 2012 at 12:47 PM, Alex Skinner <[email protected]>
>>> wrote:
>>> >>
>>> >> No because they need to be varred.
>>> >>
>>> >> On Thursday, 5 April 2012, Benjamin Davis <
>>> [email protected]> wrote:
>>> >> > Thanks Alan!
>>> >> > I see what part of the problem here is.  When you dumped the
>>> variables on the index page, it is coming through the call of the
>>> scanner.LoadTemplate, which has access to the full cfc.  So, to test this.
>>>  I created another function in the scanner.cfc which just returned "Hi" and
>>> then I called it from the index.cfm page
>>> with <cfoutput>#testing()#</cfoutput> and I get "Hi" on my page, so the
>>> index.cfm has full access to the scanner.cfc......
>>> >> > I guess that I'm going to have to think this through a little bit
>>> more and come up with a better solution.
>>> >> > The strange thing still though, is that shouldn't each call to the
>>> function reset its local variables?  For example, if I do a dump of the
>>> variables scope inside of my LoadTemplate function, each call to the
>>> function has the exact same variables.  Shouldn't this be reset with each
>>> call?
>>> >> > Thanks for the name info.  I didn't realize that I had done that as
>>> I was throwing this together.
>>> >> >
>>> >> > On Tue, Apr 3, 2012 at 9:29 PM, Alan Holden <[email protected]>
>>> wrote:
>>> >> >
>>> >> > It would be nice if we could post the salient parts of this code
>>> right in the mailing list, if you don't mind. You might get a broader
>>> response that way.
>>> >> >
>>> >> > NOTE: I get the same results from ACF9 as from OpenBD 2.02...  G G
>>> G Ghost Vars!! RUN! AAAAyyyyeeeeee!!
>>> >> >
>>> >> > I put this line <cfdump var="#variables#"> at the end of your
>>> index.cfm file, and I can see all the things that CF considers
>>> "un-scoped".  For example, while you DO scope application.Scanner on
>>> startup, this object has 2 methods within (LoadTemplate & LoadPage) that
>>> have popped up in the "variables" scope at the time the dump is called.
>>> >> >
>>> >> > I think the issue might come from using the OnRequest() method as
>>> the "code shell" for the whole page; also perhaps that the methods in
>>> scanner.cfc are not well encapsulated. They read from external scopes and
>>> write directly to the page, as opposed to [returning values back - from
>>> input arguments passed in], like most well-behaved functions.
>>> >> >
>>> >> > Here are some quasi-related conversations I found - that might help:
>>> >> > http://forums.adobe.com/message/2285269
>>> >> >
>>> http://stackoverflow.com/questions/8188015/do-variables-inside-application-cfc-functions-need-scoping
>>> >> > http://forums.adobe.com/thread/604831
>>> >> >
>>> http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=appFramework_04.html
>>> >> >
>>> >> > Finally, your application is named "Scanner", and you've also
>>> created an object named "Scanner" within it. Despite the referential
>>> separation by tiny dots, some people would cringe and shudder at such a
>>> naming practice.
>>> >> >
>>> >> > Al
>>> >> >
>>> >> >
>>> >> > On 4/3/2012 8:29 AM, Benjamin Davis wrote:
>>> >> >
>>> >> > Hey Alan,
>>> >> > Thanks for the info.  Attached is a zip file with the basic of
>>> basics.  In this example, the index.cfm file sets a variable and then when
>>> you to go page2.cfm, the variable is displayed, even though that page never
>>> specifically sets the variable.  Let me know what you think.
>>> >> > Thanks!
>>> >> > Ben
>>> >> >
>>> >> > On Mon, Apr 2, 2012 at 5:54 PM, Alan Holden <[email protected]>
>>> wrote:
>>> >> >
>>> >> > It certainly seems like something (perhaps that function) is
>>> definitely causing the variables scope to go zombie on you. But you may
>>> need to whittle your code down to a core sample and actually post that - to
>>> get the greatest qty of help.
>>> >> >
>>> >> > Alan Holden
>>> >> > (at work)
>>> >> >
>>> >> >
>>> >> > On 4/2/2012 2:35 PM, Ben wrote:
>>> >> >
>>> >> > So, I have an interesting case that needs some external thought.
>>>  I've created a "framework" that handles all of my security as well as
>>> combining the page that is requested into a template file.  I've made this
>>> into a cfc that is loaded into the Application Scope.  In my OnRequest
>>> function, I call another function of my framework that loads any external
>>> files, the requested file, and then the template file where everything gets
>>> combined.  This has been working great, but then I realized that if
>>> >>
>>>   >> --
>>> >> online documentation: http://openbd.org/manual/
>>> >> google+ hints/tips: https://plus.google.com/115990347459711259462
>>> >> http://groups.google.com/group/openbd?hl=en
>>> >
>>> > --
>>> > online documentation: http://openbd.org/manual/
>>> > google+ hints/tips: https://plus.google.com/115990347459711259462
>>> > http://groups.google.com/group/openbd?hl=en
>>> >
>>>
>>> --
>>> Alex Skinner
>>> Managing Director
>>> Pixl8 Interactive
>>>
>>>  Tel: +448452600726
>>> Email: [email protected]
>>>  Web: pixl8.co.uk
>>>
>>> --
>>> online documentation: http://openbd.org/manual/
>>> google+ hints/tips: https://plus.google.com/115990347459711259462
>>> http://groups.google.com/group/openbd?hl=en
>>>
>>
>>  --
>> online documentation: http://openbd.org/manual/
>> google+ hints/tips: https://plus.google.com/115990347459711259462
>> http://groups.google.com/group/openbd?hl=en
>>
>>    --
>> online documentation: http://openbd.org/manual/
>> google+ hints/tips: https://plus.google.com/115990347459711259462
>> http://groups.google.com/group/openbd?hl=en
>>
>
>  --
> online documentation: http://openbd.org/manual/
> google+ hints/tips: https://plus.google.com/115990347459711259462
> http://groups.google.com/group/openbd?hl=en
>
>  --
> online documentation: http://openbd.org/manual/
> google+ hints/tips: https://plus.google.com/115990347459711259462
> http://groups.google.com/group/openbd?hl=en
>

-- 
online documentation: http://openbd.org/manual/
   google+ hints/tips: https://plus.google.com/115990347459711259462
     http://groups.google.com/group/openbd?hl=en

Reply via email to