Range of change in CF 10 compared to CF MX7

I am having a strange problem with my ColdFusion 10 code. I am new to ColdFusion, so it’s easy on me. The reason this is strange is because it does not seem to be found in older versions of this platform (i.e. MX 7).

A little information:

I have two environments. ColdFusion 10 and ColdFusion MX 7 (IIS 7 and IIS 5, respectively). In ColdFusion 10 environment, I have an Application.cfc file with the following statement ...

 <cfset CompanyLogoText = "Acme Company"> 

This Application.cfc file is located in the root directory (mydomain.com). I also have a CFM file in a web root subfolder in mydomain.com/pages/default.cfm . It contains the following markup ...

 <cfoutput><p>#CompanyLogoText#</p></cfoutput> 

Problem

When I go to mydomain.com/pages/default.cfm , I get an error from coldfusion. Error: "COMPANYLOGOTEXT variable undefined."

Strange part

I do not get this error in ColdFusion MX 7. The only difference is that the CF MX 7 environment uses the Application.cfm file, but with the same exact line.

Question

How can I get the pages/default.cfm file to view my CompanyLogoText variable in CF 10?

Here is the complete markup

Application.cfc

 <cfcomponent> <cfset This.name = "test_cf"> <cfset This.Sessionmanagement="yes"> <cfset This.Sessiontimeout="#createtimespan(0,0,10,0)#"> <cfset This.applicationtimeout="#createtimespan(5,0,0,0)#"> <cfset This.setclientcookies="no" > <cfset This.clientmanagement="no"> <cffunction name="onApplicationStart"> <cfset CompanyLogoText = "Acme Company"> </cffunction> <cffunction name="onRequestStart"> <cfargument name="requestname" required=true /> <cfset CompanyLogoText = "Acme Company"> </cffunction> </cfcomponent> 

Pages / Default.cfm

 <cftry> <cfoutput><p>#CompanyLogoText#</p></cfoutput> <cfcatch> <p>Could not read CompanyLogoText<br/><br/> <cfoutput> <br/>Message: #cfcatch.message# <br/>Details: #cfcatch.detail#. </cfoutput> </cfcatch> </cftry> 
+7
scope coldfusion coldfusion-10
source share
3 answers

What is the difference between Application.cfm and Application.cfc

Use onRequest() , set the variables, and then cfinclude target file. This is the only way to share the scope of variables .

https://wikidocs.adobe.com/wiki/display/coldfusionen/onRequest

eg.

 <cffunction name="onRequest" returnType="void"> <cfargument name="targetPage" type="String" required=true/> <cfinclude template="globalVars.cfm"> <cfset variables.foo = "bar"> <cfinclude template="#Arguments.targetPage#"> </cffunction> 

QUOTE: CF8: transition from Application.cfm to Application.cfc

Put in the onRequest method any code that sets the scope of the Variables variables and add the cfinclude tag, which includes the page specified in the Arguments.Targetpage parameter.

+4
source share

As already mentioned, your application.cfc file must be formatted correctly. It is best to let it read and format your .cfc accordingly.

http://www.bennadel.com/blog/726-ColdFusion-Application-cfc-Tutorial-And-Application-cfc-Reference.htm

0
source share

Until the answer is displayed. If you have the application.cfm file in a subdirectory, it will override application.cfc in the root. Just an opportunity ...

0
source share

All Articles