Barney suggested adding your DSN, UN, and PW as actual arguments to
the function.

I've been using the way of the Jedi, Ray Camden :), lately.  Setup a
config.ini file with your dsn name, un, pw, etc.. and have your CFC
read theses values in when its instantiated.  I've actually gone a
step further and created a 'parent' CFC that my other CFCs extend.
This parent holds the config.ini settings.

Doug

----- Original Message -----
From: dave <[EMAIL PROTECTED]>
Date: Wed, 22 Sep 2004 21:45:39 -0400
Subject: Re: cfc variables
To: CF-Talk <[EMAIL PROTECTED]>

not real sure how that would work

say i have the cfc

<!--- get agents name --->
<cfcomponent>
   <cffunction name="mainpage" access="public" returntype="query"
hint="get mainpage info">
     <!--- set site dsn connection --->
<cfset dsn = "whenever">
<cfset un = "whoever">
<cfset pw = "whatever">
        <cfquery name="qMP" datasource="#dsn#" username="#un#" password="#pw#">
         SELECT *
         FROM mainpage
         </cfquery>
    <cfreturn qMP>
  </cffunction>
</cfcomponent>

and then the object call from the application.cfm template

<cfobject name="amainPage" component="components.mainpage">

how would it be put in?

thanks :)



---------- Original Message ----------------------------------
From: Barney Boisvert <[EMAIL PROTECTED]>
Reply-To: [EMAIL PROTECTED]
Date:  Wed, 22 Sep 2004 18:17:07 -0700

>What scope are you setting them into?  Each CFC instance has it's own
>'variables' scope, but it can reference any of the shared scopes (app,
>session, server) and any of the request scopes (url, form, request,
>client).
>
>However, before you change that, you're almost always better off
>passing in values to your CFCs (with the init() method), rather than
>letting your CFCs reference any external variables.  When you
>instantiate your CFC, just pass along your DSN and whatever else, and
>store it inside the CFC.  That way you stick with only having a single
>place to record the data (Application.cfm), and you don't have your
>CFCs referencing external variables anywhere.
>
>cheers,
>barneyb
>
>
>On Wed, 22 Sep 2004 21:09:43 -0400, dave <[EMAIL PROTECTED]> wrote:
>> i have never seen an explanation for this and maybe i am on crack
again but.....
>>
>> say i have the db connection variables in cfc
>> why wont they read from the Application.cfm file?
>>
>> or will they? when i set it up to read it that way it fails
>>
>> kinda a PITA to go into every cfc to do it
>>
>>
>
>________________________________
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to