Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Oct 04, 2012 Oct 04, 2012

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>

TOPICS
Getting started
800
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 07, 2012 Oct 07, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 07, 2012 Oct 07, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 10, 2012 Oct 10, 2012
LATEST

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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources