Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Application.cfc Issues

Guest
Sep 30, 2009 Sep 30, 2009

We are migrating a cf6 app to cf8 and I've run into an issue with the application.cfc. In my old application.cfm page the following code - in bold, creates a reference to an object, in the new cfc model this does not work.

old application.cfm page

<cffunction name="loadAppCFC" access="public" displayname="Load CFC module" hint="Load CFCs into the application scope">
    <cfargument name="ObjectName" REQUIRED="Yes" TYPE="variableName">
    <cfargument name="LocalName" type="variableName" default="#Arguments.ObjectName#">
    <cfargument name="Reload" type="string" default="n">

    <cfif Arguments.Reload eq "y" OR NOT IsDefined("Application.Obj.#Arguments.ObjectName#") OR ISDefined("Application.CFCReload.#Arguments.ObjectName#")>
        <CFTRACE text="Reloading cfc object #Arguments.ObjectName# - #ISDefined('Application.CFCReload.#Arguments.ObjectName#')#">
        <cflock timeout="5" throwontimeout="Yes" name="#Arguments.ObjectName#" type="EXCLUSIVE">
            <cfobject name="Application.Obj.#Arguments.LocalName#" component="\ECConfig\Components\Lib\#Arguments.ObjectName#">
            <CFIF IsDefined("Application.CFCReload")>
        <cfset StructDelete(Application.CFCReload, Arguments.ObjectName, "True")>
            </CFIF>
        </cflock>
    </cfif>
     <cfset Variables[Arguments.LocalName] = evaluate("Application.Obj.#Arguments.LocalName#")>
</cffunction>

new application.cfc page

<cfcomponent>
.
.function above is defined here
.
<cffunction name="onApplicationStart" returntype="boolean">
.
.
<cfset loadAppCFC("comUDF", "comUDF", Application.ini.debug.ReloadObjects)>
.
.
<cfreturn true/>
</cffunction>
</cfcomponent>


Using the old application page we can reference the object as comUDF.methodName, using the new application page this does not work and I have to instead use Application.Obj.comUDF.methodName. I am trying to avoid this as we have a very large number of pages that use these calls. If anyone can point out how I can create a reference to this object it would be greatly appreciated.

873
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Sep 30, 2009 Sep 30, 2009

For the variable scope issue, it is a matter of putting it in the proper place.

OnApplicationStart(): you can define "applicaiton" scope variables

OnSessionStart(): You can define "session" scope variables.

OnRequestStart(): You can define "request" scope variables AND "varaiables" scope variables if you also include on OnRequest method.

OnRequest(): You can define"variables" scope variables or allow for them to be defiend on the OnRequestStart() method.

On note is using the OnRequest() method can have impoprtant consequences to CFML pages intended to be used as web services or for remote AJAX and or Flex AMF requests.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 30, 2009 Sep 30, 2009

Okay I tried setting this variable in the onRequest scope, but it does not work. When I hit my breakpoint in my application and look at the Variables scope the variable comUDF does not exist, it should be a reference to the Application.Obj.comUDF component.

Can I use evaluate inside the onRequest scope?

<cfset Variables["comUDF"] = evaluate("Application.Obj.comUDF")>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 01, 2009 Oct 01, 2009

Okay I tried setting this variable in the onRequest scope, but it does not work. When I hit my breakpoint in my application and look at the Variables scope the variable comUDF does not exist, it should be a reference to the Application.Obj.comUDF component.

Can I use evaluate inside the onRequest scope?

<cfset Variables["comUDF"] = evaluate("Application.Obj.comUDF")>

You can, but why would you want to in this case?

One can also certainly set variables-scoped variables in onRequest() and they are available to the template onRequest() includes.

Here's a brief proof of concept:

<!--- Application.cfc --->

<cfcomponent output="false">
   
    <cfset this.name = "app1">


    <cffunction name="onRequest" returnType="void">
        <cfargument name="thePage" type="string" required="true">
       
        <cfset variables.foo = "bar">
       
        <cfinclude template="#arguments.thePage#">
    </cffunction>


</cfcomponent>


<!--- dump.cfm --->

<cfdump var="#variables#">

Stick those in the same dir, and browse to dump.cfm.  You'll see foo in the variables scope.

So I'm not sure why you're having problems.  Post your code.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 01, 2009 Oct 01, 2009
LATEST

Turns out I put the variable definition in the wrong section of the code. Thanks for everyon'e help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 30, 2009 Sep 30, 2009

I would first try simpler expressions like

<cfset Variables[Arguments.LocalName] = application.Obj[Arguments.LocalName]>
<cfset Variables.comUDF = Application.Obj.comUDF>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources