在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(表单)
/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的方式之前,这个查询是有效的。
发布于 2011-08-15 11:46:46
不要将表单作用域传递给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" />https://stackoverflow.com/questions/7061247
复制相似问题