|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I'm using MX7 and following Forta's latest book pretty closely (pages 622-629). Below is my application file. When I run a page that attempts to call any of the application variables, I get an error message saying that the variable is undefined. What have I done wrong?
Thanks, Jason Code:
<CFCOMPONENT OUTPUT="false">
<CFPARAM NAME="Title" Default="">
<!--- Name the application. --->
<CFSET this.name="HumanSexuality">
<!--- Turn on session management. --->
<CFSET this.sessionManagement=true>
<CFFUNCTION NAME="onApplicationStart" OUTPUT="false" RETURNTYPE="void">
<!--- Any variables set here can be used by all our pages --->
<CFSET APPLICATION.dataSource = "courses">
<CFSET APPLICATION.DSN = "courses">
<CFSET APPLICATION.siteURL = "http://209.200.109.186/">
<CFSET APPLICATION.CurrentGradeTable = "S05_253_Grades">
<CFSET APPLICATION.companyName = "FAM 253: Human Sexuality">
</CFFUNCTION>
<CFFUNCTION NAME="onRequestStart" OUTPUT="false" RETURNTYPE="void">
<CFINCLUDE TEMPLATE="header.cfm">
<!--- <CFINCLUDE template="course_counter.cfm"> --->
</CFFUNCTION>
<!--- If user is not logged in, force them to now --->
<CFIF not isDefined("SESSION.auth.isLoggedIn")>
<!--- If the user is now submitting "Login" form, --->
<!--- Include "Login Check" code to validate user --->
<CFIF isDefined("UserLogin.SSN")>
<CFINCLUDE TEMPLATE="loginCheck.cfm">
</CFIF>
<CFINCLUDE TEMPLATE="loginForm.cfm">
<CFABORT>
</CFIF>
<!--- After the page loads. --->
<CFFUNCTION NAME="onRequestEnd" RETURNTYPE="void" OUTPUT="true">
<CFINCLUDE TEMPLATE="footer.cfm">
</CFFUNCTION>
</CFCOMPONENT>
|
|
#2
|
|||
|
|||
|
How are you calling the application variable on the .cfm page? Are you calling with Application.myvariable or just myvariable?
|
|
#3
|
|||
|
|||
|
I would start by creating a simple 1 page application with an Application.cfc file, and have nothing in there except one application variable assignment. The key is to get rid of everything that is not related to the problem and then do your troubleshooting.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#4
|
|||
|
|||
|
I broke it down about as simply as possible, but I still get the same error. Specifically, I get the application.datasource not defined error when I run Test.cfm and have nothing but the application variable in the application file. (When I replace the datasource with "courses" in the query it works fine.)
Thanks, Jason Code:
<!--- Test.cfm ---> <CFQUERY NAME="test" DATASOURCE="#APPLICATION.datasource#"> SELECT * FROM S05_253_Grades </CFQUERY> <CFOUTPUT QUERY="test"> #FIRSTNAME#, #LASTNAME#<BR> </CFOUTPUT> Code:
<!--- Application.cfc --->
<CFCOMPONENT OUTPUT="false">
<CFFUNCTION NAME="onApplicationStart" OUTPUT="false" RETURNTYPE="void">
<CFSET APPLICATION.dataSource = "courses">
</CFFUNCTION>
</CFCOMPONENT>
|
|
#5
|
|||
|
|||
|
I'm not sure yet what I did to get this working, but it seems to be working properly now.
Thanks, Jason |
|
#6
|
|||
|
|||
|
I would almost guarantee that when you added the application variables to the onApplicationStart() method, the application had *already been started*. In other words, since onApplicationStart() only runs the very first time an applicaiton is initialized, you'd either have to restart the CFMX service or explicitly add code that you can run to recall onApplicationStart() in order for your applicaiton variables to be created.
So you could run a URL like "index.cfm?refresh=true", and then in your onRequestStart() method you could have: <cfif structKeyExists( url, 'refresh' )> <cfset onApplicationStart() /> </cfif> which would force a refresh of your application variables because the onApplicationStart() method would be re-run. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Application variables not found :mad: |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|