?
Solved

Coldfusion 9 application variable to set file path

Posted on 2011-09-23
6
Medium Priority
?
274 Views
Last Modified: 2012-05-12
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.homePage#">Home</a></cfoutput>

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?
0
Comment
Question by:roger_v
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 13

Accepted Solution

by:
ansudhindra earned 2000 total points
ID: 36588270
did you try restarting the server?
try putting '\\' instead of '\'...
0
 
LVL 1

Author Comment

by:roger_v
ID: 36588320
@ansudhindra:

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.
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 36588582
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.



0
Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

 
LVL 39

Expert Comment

by:gdemaria
ID: 36588595
> 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

0
 
LVL 1

Author Closing Comment

by:roger_v
ID: 36591199
That worked!
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 36591202
what worked?
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question