Friday, March 26, 2010

Application.cfm

I am pretty new to CFC's but i just finished creating one and
i am trying to use some global variables that i have defined in my
Application.cfm but that doesn't seem to work.



Can CFC's use global variables that are defined in
Application.cfm? If not is there a way to accomplish this?Application.cfm
CFCs are designed to be available to more than one
application. The most effective way to use them is to pass those
variables to the functions as arguments.Application.cfm
Yes CFC's can use global variables but most developers
consider this a

poor practice. The generally considered best practice is that
a CFC

(object) should be passed any and all data it is expected to
use.



But if you desire the CFC to use global variables it needs to
be part of

the 'application'. This is defined by the %26lt;cfapplication
....%26gt; tag name

property or application.cfc this scope name variable. If the
CFC is not

under a directory with an Applciation.cfm with the
%26lt;cfapplication...%26gt;

tag or Application.cfc it will need it's own
%26lt;cfapplication...%26gt; tag with

a matching name parameter.



It's all about the name. All CF code templates running under
the same

name share the same global variables.



No comments:

Post a Comment