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

variable soring

Participant ,
Mar 05, 2009 Mar 05, 2009
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?
TOPICS
Advanced techniques
272
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
Advocate ,
Mar 05, 2009 Mar 05, 2009
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
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 ,
Mar 05, 2009 Mar 05, 2009
LATEST
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.
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