I would re-write the first 3 lines of myForm.cfm. Right now you have

<cfset myObj = CreateObject("Component","Components.myComponent")>
<cfset Temp = myObj.Init(Application.DSN)>
<cfset myQry = myObj.myFunction (ID)>

A more accepted way of writing this is:

<cfset myObj = CreateObject("Component","Components.myComponent").init(Application.DSN)>
<cfset myQry = myObj.myFunction(ID)>

Now, for this to work you have to have your init() method return a reference to the object being created.  Just add a "<cfreturn this>" line to the end of your init() method.

On 1/17/06, Phillip Senn <[EMAIL PROTECTED]> wrote:

Can someone look over this simplified example and tell me if this is the best practice for doing a standard query using components?

I'm particularly fretting over Variables.DSN.

I'm totally open to changes, no worries about hurting my feelings.

 

 

 

myForm.cfm contains:

 

<cfset myObj = CreateObject("Component","Components.myComponent")>

<cfset Temp = myObj.Init(Application.DSN)>

<cfset myQry = myObj.myFunction(ID)>

 

<body>

<cfdump var="myQry">

</body>

</html>

 

 

MyComponent.cfc contains:

 

<cfcomponent output="False">

 

<cffunction name="Init" output="False" returntype="void">

<cfargument name="DSN" required="yes">

<cfset Variables.DSN = arguments.DSN>

</cffunction>

 

<cffunction name="myFunction" output="False" returntype="query">

                <cfargument name="ID" type="numeric">

                <cfset var result = "">

                <cfquery name="result" datasource="#Variables.DSN#">

                SELECT * FROM myTable WHERE myTableID = #arguments.myTableID#

                </cfquery>

                <cfreturn result>

</cffunction>

 

</cfcomponent>

----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.

CFCDev is run by CFCZone ( www.cfczone.org) and supported by CFXHosting ( www.cfxhosting.com).

An archive of the CFCDev list is available at www.mail-archive.com/[email protected]

----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).

An archive of the CFCDev list is available at www.mail-archive.com/[email protected]

Reply via email to