roger v
asked on
Coldfusion 9 application variable to set file path
Hi,
I'm having a problem setting an application variable to specify the path to my home page. It seemed simple enough but I keep getting a application variable not defined error. My home page is index.cfm and on every other subsequent page I have a link back to the index page. I set the path to the index.cfm in my application.cfc's on application start function like so:
<cfset application.homePage = "\races\index.cfm" />
And on all the pages I have the following:
<cfoutput><a href="#application.homePag e#">Home</ a></cfoutp ut>
But I get application.homePage is undefined error. How do I set this so that I don't have to hardcode the path on three different environments - dev, stage and production?
I'm having a problem setting an application variable to specify the path to my home page. It seemed simple enough but I keep getting a application variable not defined error. My home page is index.cfm and on every other subsequent page I have a link back to the index page. I set the path to the index.cfm in my application.cfc's on application start function like so:
<cfset application.homePage = "\races\index.cfm" />
And on all the pages I have the following:
<cfoutput><a href="#application.homePag
But I get application.homePage is undefined error. How do I set this so that I don't have to hardcode the path on three different environments - dev, stage and production?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hey Roger -
First, let's make sure your application.cfc has good app variable set. You want to be sure application management is turned on with a nice long timeout period
Something like this should be at the top of your application.cfc file...
<cfcomponent output="false">
<cfset this.name = "mywebsite">
<cfset this.applicationTimeout = createTimeSpan(0,4,0,0)>
<cfset this.sessionManagement = true>
<cfset this.setClientCookies = true>
<cfset this.sessionTimeout = createTimeSpan(0,0,50,0)>
<cfset this.setdomaincookies = true>
This is in your onApplicationStart function... just to be picky, please get rid of the / at the end and change the slashes to / instead of \
<cfset application.homePage = "\races\index.cfm" />
becomes...
<cfset application.homePage = "/races/index.cfm">
Now, onApplicationStart will only fire when the application renews, that is, after the timeout period has expired. So the variable will not be defined until the next time the app is refreshed. You can restart the service (not the server, the service) or even easier, just make a small change to the application name at the start of your application.cfc file...
If it was ...
<cfset this.name = "mywebsite">
change it to anything else...
<cfset this.name = "myBestWebsite">
That will force a new application and the variables will be loaded.
First, let's make sure your application.cfc has good app variable set. You want to be sure application management is turned on with a nice long timeout period
Something like this should be at the top of your application.cfc file...
<cfcomponent output="false">
<cfset this.name = "mywebsite">
<cfset this.applicationTimeout = createTimeSpan(0,4,0,0)>
<cfset this.sessionManagement = true>
<cfset this.setClientCookies = true>
<cfset this.sessionTimeout = createTimeSpan(0,0,50,0)>
<cfset this.setdomaincookies = true>
This is in your onApplicationStart function... just to be picky, please get rid of the / at the end and change the slashes to / instead of \
<cfset application.homePage = "\races\index.cfm" />
becomes...
<cfset application.homePage = "/races/index.cfm">
Now, onApplicationStart will only fire when the application renews, that is, after the timeout period has expired. So the variable will not be defined until the next time the app is refreshed. You can restart the service (not the server, the service) or even easier, just make a small change to the application name at the start of your application.cfc file...
If it was ...
<cfset this.name = "mywebsite">
change it to anything else...
<cfset this.name = "myBestWebsite">
That will force a new application and the variables will be loaded.
> How do I set this so that I don't have to hardcode the path on three different environments - dev, stage and production?
Here's the bigger question - why are your three different environments different? They should all be identical.. at least from the web root down.
Also, why isn't your home page at your web root? If I were to take someone to my home page, all I would need to do is this...
<a href="/"> Go Home </a>
That is all it takes to go back to the root and execute the default file in your web root
Here's the bigger question - why are your three different environments different? They should all be identical.. at least from the web root down.
Also, why isn't your home page at your web root? If I were to take someone to my home page, all I would need to do is this...
<a href="/"> Go Home </a>
That is all it takes to go back to the root and execute the default file in your web root
ASKER
That worked!
what worked?
ASKER
No I did not try restarting the cf server. I'll get that a shot as well as '\\'. Will let you know in just a few.