首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >调用CFC的问题

调用CFC的问题
EN

Stack Overflow用户
提问于 2011-08-15 02:42:36
回答 1查看 425关注 0票数 0

在CFM中,我调用CFC (cfc命名为Customers,方法或函数称为ModifyCustomers),如下所示:

代码语言:javascript
复制
cfform method="post" action="?">
     <input type="hidden" action="ModifyCustomers" > 
...rest of form...

然后..。

代码语言:javascript
复制
<!--- 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文件在同一个目录中。

代码语言:javascript
复制
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代码的一部分:

代码语言:javascript
复制
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的方式之前,这个查询是有效的。

EN

回答 1

Stack Overflow用户

发布于 2011-08-15 11:46:46

不要将表单作用域传递给CFC,而是尝试这样做:

代码语言:javascript
复制
<cfset AbcCFC.ModifyCustomers(argumentCollection = FORM) />

这将将表单结构的各个项作为单独的参数传递,而不是简单地传递整个结构,即表单范围。

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

代码语言:javascript
复制
<cfif structKeyExists( form, "action" ) AND form.action EQ "ModifyCustomers" >

最后,您的属性为“action”。没有这样的属性。我想你的意思是:

代码语言:javascript
复制
<input type="hidden" name="action" value="ModifyCustomers" />
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7061247

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档