2011-08-15 18 views
0

在我的CFM,我打电话给我的CFC(氟氯化碳被命名为客户和方法或函数被调用ModifyCustomers)象下面这样:问题致电CFC

cfform method="post" action="?"> 
    <input type="hidden" action="ModifyCustomers" > 
...rest of form... 

然后...

<!--- determine whether form was submitted and what action is ---> 

cfif isDefined("FORM") and isDefined("Action") and Action eq "ModifyCustomers"> 

    !--- create object for cfc --- 

cfset AbcCFC = createObject("component", "customers") 


--- drop form data into method --- 

cfset AbcCFC.ModifyCustomers(FORM)> 


!--- the method will do stuff from form data---> 


!--- result from the call to the method --- 

cfset wasBigSuccess = abcCFC.ModifyCustomers(FORM) 

但是,看起来像我的CFC没有被称为.....有什么建议吗?

更新

是的,我的CFC文件在同一目录下。

cfform method="post" action="?" 

input type="hidden" action="ModifyCustomers" 
...rest of form 

/cfform (end of form) 



!--- determine whether form was submitted and what action is --- 

cfif isDefined("FORM") and isDefined("Action") and Action eq "ModifyCustomers" 

    !--- create object for cfc --- 

cfset AbcCFC = createObject("component", "customers")/


!--- drop form data into method --- 

cfset AbcCFC.ModifyCustomers(FORM) 

方法将运行...

检查结果... CFSET wasBigSuccess = AbcCFC.ModifyCustomers(FORM)

/CFIF

部分的CFC代码:

cffunction name="ModifyCustomers" access="remote" returntype="String" output="false" 

     hint="Modify customers in the database" 

    cfargument name="firstname" required="yes" type="string" 

    cfargument name="lastname" required="yes" type="string" 

    cfargument name="email"  required="yes" type="string" 

    cfargument name="manage" required="yes" type="string" 

    cfset var Customers = "" 

    cfset var retVal = "0" 

    cfset final = "0" 

    <!--- If manage = Subscribe, run Addcustomers query. If record count is 0, user is already 
     in the database, if record count is 1, query successflly ran and added user. Email is set as Unique 
     in the database, so I used an "Ignore" below to bypass the system generated error and will show message 
     stating that the user is already in database for newsletter---> 

     <cfif Manage eq "Subscribe"> 
       <cfquery name="Addcustomers" datasource="LizDataSource" result="final"> 
    INSERT IGNORE INTO users (firstname, lastname, email) 
      VALUES(
      <cfqueryparam value="#trim(form.firstname)#" cfsqltype="cf_sql_varchar">, 
      <cfqueryparam value="#trim(form.lastname)#" cfsqltype="cf_sql_varchar">, 
      <cfqueryparam value="#trim(form.email)#"  cfsqltype="cf_sql_varchar"> 
       )  
       </cfquery> 

       <cfif final.recordcount is "0"> 
       <cfset retVal = "0"> 

        <!---<cfoutput> Email #form.email# is already subscribed to the newsletter! 
        </cfoutput> ---> 

        <cfreturn retVal> 

我的表单数据没有写入我的数据库。在我改变我调用CFC的方式之前,查询正在工作。

+0

你确定你的createObject()是正确的吗? Customers.cfc与cfm文件位于同一目录中吗?如果不是,则createObject()的第二个参数应该是以点表示形式指向CFC的路径。例如'createObject('component','path.to.Customers')' – charliegriefer

+0

如果你可以附上有帮助的代码。 –

+0

是什么让你相信它没有被召唤?你有错误吗?如果是这样,有什么错误?另外,它看起来像你正在调用ModifyCustomers()两次。是这样吗?还是仅仅是示例代码?另外,ModifyCustomer是否返回布尔值?正如戴尔所说,这将有助于查看更多的代码,包括CFC功能。 –

回答

0

这是因为您没有从CFM文件传递“管理”参数给CFC?

1

相反的形式范围传递给你的CFC,试着这样做:

<cfset AbcCFC.ModifyCustomers(argumentCollection = FORM) /> 

这将通过形式结构个别参数的个别项目,而不是简单地通过整个结构的形式范围。

另外,isDefined(“form”)将在每个页面上返回true。相反,你应该做一些事情:

<cfif structKeyExists(form, "action") AND form.action EQ "ModifyCustomers" > 

最后,你有一个'行动'的属性。没有这样的属性。我假定你的意思是:

<input type="hidden" name="action" value="ModifyCustomers" />