在我的CFM中,我正在调用我的CFC(cfc名为Customers,方法或函数名为ModifyCustomers),如下所示:
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 :(得分:1)
不要将表单范围传递给CFC,而是尝试这样做:
<cfset AbcCFC.ModifyCustomers(argumentCollection = FORM) />
这会将表单结构的各个项目作为单独的参数传递,而不是简单地传递作为表单范围的整个结构。
此外,isDefined(“form”)将在每个页面上返回true。相反,你应该做点什么:
<cfif structKeyExists( form, "action" ) AND form.action EQ "ModifyCustomers" >
最后,你有一个'action'属性。没有这样的属性。我认为你的意思是:
<input type="hidden" name="action" value="ModifyCustomers" />
答案 1 :(得分:0)
因为你没有通过&#34;管理&#34; CFM文件中CFC的参数?