Skip to main content
Inspiring
June 24, 2008
Question

CFC Init problem

  • June 24, 2008
  • 2 replies
  • 348 views
I'm trying to create a cfc in my application scope but the variables I set in the init method don't seem to be persistent. Here is the init method:

<cfcomponent displayname="coupons" hint="Checks validity and type of coupon and applies it to order."> <cffunction name="init" access="public" output="false" returntype="coupon"> <cfargument name="ds" required="true" type="string" <cfset variables.ds=arguments.ds> <cfreturn this> </cffunction>

Here's the call in the Application.cfc

<cfset Application.coupons = createObject("component", "coupon").init(application.admin.ds)>

Here is the method that throws the "variables.ds not defined error"

<cfstoredproc procedure="pr_getCouponList" datasource="#variables.ds#" debug="Yes"> <cfprocparam type="In" cfsqltype="CF_SQL_INTEGER" dbvarname="@Active" value="#arguments.Active#" null="No"> <cfprocparam type="In" cfsqltype="CF_SQL_VARCHAR" dbvarname="@Sort" value="#arguments.gridSortColumn#" null="No"> <cfprocresult name="getCouponList" resultset="1"> </cfstoredproc>
This topic has been closed for replies.

2 replies

Inspiring
June 24, 2008
On Tue, 24 Jun 2008 05:22:30 +0000 (UTC), athanasiusrc wrote:

> Okay, I figured out the problem but don't know the answer. I am getting this
> problem when I try to bind the cfc in a grid because the grid is binding a new
> copy of the cfc instead of the one created in the application scope:
>
> <cfgrid format="html" name="getCouponList" pagesize="#attributes.pageSize#"
> selectmode="row"
>
> bind="cfc:cfcs.coupon.getCouponList({cfgridpage},{cfgridpagesize},{cfgridsort
> column},{cfgridsortdirection},{active})">
>
> It works if I call it through an invoke command.
>
> The problem I have now is, how can I bind a cfc in a scope?


I'm not sure how to use a variable instead of a CFC in a bind statement (I
don't do much UI type development, so have never needed to know); however
your init() method in your CFC could look to see if there's an instance of
itself in the application scope and if so return that instead of a new
instance of itself. Then you chain your method call thus:

cfcs.coupon.init().getCouponList(etc...)

--
Adam
Inspiring
June 24, 2008
Okay, I figured out the problem but don't know the answer. I am getting this problem when I try to bind the cfc in a grid because the grid is binding a new copy of the cfc instead of the one created in the application scope:

<cfgrid format="html" name="getCouponList" pagesize="#attributes.pageSize#" selectmode="row"
bind="cfc:cfcs.coupon.getCouponList({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection},{active})">

It works if I call it through an invoke command.

The problem I have now is, how can I bind a cfc in a scope?