В моем 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.