Skip to main content
Known Participant
October 4, 2012
Question

Where is the best place to set the path with Application.cfc?

  • October 4, 2012
  • 2 replies
  • 861 views

Hi!

When I used Application.cfm, I set many path variables here so I don't have to keep writing a full path on many of the templates repeatedly.

So I did:

<CFSET FileArchives = "/space/users/www/FileArchives/#session.Groups#/">

<CFSET GoodFiles = "/space/users/www/GoodFiles/#session.usergroup#/">

etc...

Later on I only need to refer it as: #FileArchives# in the codes instead of a full path name.

Now that I'm using Application.cfc can I also do the same thing???? should I do it within OnApplicationStart function? am I doing it correctly? (see below)

     <cffunction name="onApplicationStart" returnType="boolean" output="false">

  

           <cfset application.dsn = "EMBB">

              

          <CFSET application.FileArchives = "/space/users/www/FileArchives/#session.Groups#/">

          <CFSET application.GoodFiles = "/space/users/www/GoodFiles/#session.usergroup#/">

         <cfreturn true />

  

     </cffunction>

This topic has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
October 10, 2012

This statement is almost always a fundamental design flaw: <cfset application.first_var = session.second_var>. The variable second_var is meant to be for a particular user session. Whereas first_var applies to everyone using the application.

You could do something alomg the lines of:

<cffunction name="onSessionStart" output="false">

<cfset session.groups = some_value>

<cfset session.usergroups = other_value>

<cfset session.FileArchives = "/space/users/www/FileArchives/#session.Groups#/">

<cfset session.GoodFiles = "/space/users/www/GoodFiles/#session.usergroup#/">

</cffunction>

Inspiring
October 7, 2012

Setting application variables in OnApplicationStart is a good idea.  However, referring to session variables in the OnApplicationStart function is not.

Inspiring
October 7, 2012

Dan Bracuk wrote:

Setting application variables in OnApplicationStart is a good idea.  However, referring to session variables in the OnApplicationStart function is not.

Indeed.  Wading through this lot - http://adamcameroncoldfusion.blogspot.co.uk/2012/08/more-on-applicationcfc-when-things-run.html - might be helpful for the OP to get a handle on when things run, and when things become available.

But the session scope is not available in onApplicationStart().

--

Adam