Skip to main content
Inspiring
October 8, 2008
Question

Application Variables vs Request Variables

  • October 8, 2008
  • 24 replies
  • 1875 views
I've read a number of forums and cf books but they seem to contradict each other.

To me it seems better to put say the datasourcename into the application variable -- but I dont seem able to use #APPLICATION.varname# in my pages (cf8). Am I doing something wrong?

Alternatively #REQUEST.varname# I can use no problem but this to me is requiring the cf server to do unnecessary extra work (ie before each page request) is it not?

Thanks in advance,
    This topic has been closed for replies.

    24 replies

    Inspiring
    October 8, 2008
    <body>

    <cfdump var="#APPLICATION.companyName#">

    </body>
    </html>

    Throws an error. Must I restart the cf server each time I make a change to Application.cfc? (and if so is there an easy way to restart the cf server?)
    Inspiring
    October 8, 2008
    <cfcomponent output="false">


    <cfscript>
    //the application name (should be unique)
    THIS.name = "olo";
    //how long the application variables persist
    THIS.applicationTimeout = createTimeSpan(0,2,0,0);
    //define whether client variables are enabled
    THIS.clientManagement = true;
    //where should we store them, if enabled?
    THIS.clientStorage = "cfClientVariables"; //cookie||registry||datasource
    //define where cflogin information should persist
    THIS.loginStorage = "session"; //cookie||session
    //define whether session variables are enabled
    THIS.sessionManagement = true;
    //how long the session variables persist?
    THIS.sessionTimeout = createTimeSpan(0,0,20,0);
    //define whether to set cookies on the browser?
    THIS.setClientCookies = true;
    //should cookies be domain specific
    //i.e. *.domain.com or www.domain.com
    THIS.setDomainCookies = false;
    //should we try to block cross-site scripting?
    THIS.scriptProtect = false;
    //should we secure our JSON calls?
    THIS.secureJSON = false;
    //use a prefix in front of JSON strings?
    THIS.secureJSONPrefix = "";
    //used to help ColdFusion work with missing files
    //and directory indexes. tells ColdFusion not to call
    //onMissingTemplate method.
    THIS.welcomeFileList = "";
    //define custom coldfusion mappings.
    //Keys are mapping names, values are full paths
    THIS.mappings = structNew();
    //define a list of custom tag paths.
    THIS.customtagpaths = "";
    </cfscript>


    <cffunction name="onApplicationStart" returnType="boolean" output="false">
    <cfset APPLICATION.companyName = "MyCompany">

    <cfreturn true />
    </cffunction>
    Inspiring
    October 8, 2008
    > I've read a number of forums and cf books but they seem to contradict each
    > other.
    >
    > To me it seems better to put say the datasourcename into the application
    > variable
    >
    > Alternatively #REQUEST.varname#

    Some "confusion" arose on this sort of topic in old versions of CF (prior
    to 6) in that they were very buggy when it came to doing even simple
    operations with shared-scope variables (server, application, session). The
    solution to this was to <cflock> every single access to this sort of
    variable. What a pain in the bum that was. As such, people shunned them -
    and adviseably so - for things like DSNs, because it would mean either
    locking the entire query (bad), or copying the application-scoped DSN into
    some other request-specific scope (most often the request scope).

    However that's been fixed since CFMX6.

    Variables that are global to the application should be put in the
    application scope. Variables that are global to a request should be put in
    the request scope. Almost always, a DSN is going to be global to the
    application, so application.dsn is the better fit there.


    > -- but I dont seem able to use #APPLICATION.varname# in my pages
    > (cf8). Am I doing something wrong?

    Quite possibly. But how do you expect us to answer that sensibly without
    you showing us the relevant code? Guess? I therefore guess that - yes -
    you are definitely doing something wrong ;-)


    > I can use no problem but this to me is
    > requiring the cf server to do unnecessary extra work (ie before each page
    > request) is it not?

    Correct. But the specifics of this DSN thing aside, a bigger concern is
    getting this application scope working. Because it should (work).

    --
    Adam
    Inspiring
    October 8, 2008
    > To me it seems better to put say the datasourcename into the application
    > variable -- but I dont seem able to use #APPLICATION.varname# in my pages
    > (cf8). Am I doing something wrong?
    >

    Must be, because I use application variable all the time in my CF8 CFML
    code and have been since I started using ColdFusion with version 4.5.

    But since I do not know what you are doing, I can say much about *why*
    you are having difficulty using application variables in your code.