2 Replies Latest reply on Mar 5, 2009 11:01 AM by Newsgroup_User

    variable soring

    TiGGi Level 1
      Hi all,

      I am just wondering what would be the optimal way of storing variables that are used throughout the site.
      You now like if I want to set default page title, or maybe a default number of records per page...

      Application.cfc/cfm?
      Database?
      flat text configuration file?
      Other?
        • 1. Re: variable soring
          craigkaminsky Level 3
          Hi,

          In a "standard" (i.e., no framework) CF application, I think Application.cfc (for CF 7+) is an ideal location. If you're using a framework (i.e., Fusebox, Model-Glue, ColdBox, etc.), the each framework has their own locations that are ideal for this task.

          I like Application.cfc because you can use the appropriate method for scoping your variables. For example, the onApplicationStart method is an excellent place to put your default application-scoped variables.

          Cheers,
          Craig
          • 2. Re: variable soring
            Level 7
            TiGGi wrote:
            > Hi all,
            >
            > I am just wondering what would be the optimal way of storing variables that
            > are used throughout the site.
            > You now like if I want to set default page title, or maybe a default number of
            > records per page...
            >
            > Application.cfc/cfm?
            > Database?
            > flat text configuration file?
            > Other?
            >

            Well, those choices are options for persisting data.

            To store variables that are used throughout the site the choices you
            want to be considering is what scope to put them in. The answer to that
            question is what do you want to do with the data in the variable, how
            long do you want it to live and how global do you want the data to be.

            A few of your choices are:

            SCOPE
            -----
            variables - the local scope of the template, variables scoped data is
            lost at the end of the request.

            request - local to the request, global to any and all included templates
            used to build the ruquest. Data is lost at the end of the request.

            session - local to the user, global to all requests processed for this
            session. Data is lost when session times out after a period of no new
            requests or server is restarted.

            application - local to the application, global to all requests that
            share the same string for an application name. Data is lost when
            application times out or server is restarted.

            server - global to every request processed by the ColdFusion server.
            Data is lost when server is restarted.

            Some other scopes of which to be aware.
            VAR (i.e. function local variables, accessed with no scope name)
            this (public variables in a CFC component)
            form (data received from a post request)
            url (data received from a get request)
            cgi (data provided by the web server)
            arguments (data passed into a function)
            attributes (data passed into a custom tag)
            etc.