将表单范围传递给远程 cfc
使用 access="remote" 将表单范围传递到 cfc 的语法是什么? 我有:
<cfcomponent>
<cfset Variables.Datasource = "xxx">
<cffunction name="Save" access="remote">
<cfset var local = {}>
<!--- todo: try/catch --->
<cfif arguments.PersonID>
<cfquery datasource="#Variables.Datasource#">
UPDATE Person
SET FirstName = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.FirstName#">
,LastName = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.LastName#">
WHERE PersonID = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.PersonID#">
</cfquery>
<cfset local.result = arguments.PersonID>
<cfelse>
<cfquery name="local.qry" datasource="#Variables.Datasource#">
INSERT INTO Person(FirstName,LastName) VALUES(
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.FirstName#">
,<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.LastName#">
);
SELECT PersonID FROM Person
WHERE PersonID=Scope_Identity()
</cfquery>
<cfset local.result = local.qry.PersonID>
</cfif>
<cfreturn local.result>
</cffunction>
</cfcomponent>
我需要传入form.PersonID,form.firstname,form.lastname。
What is the syntax for passing the form scope into a cfc with access="remote"?
I have:
<cfcomponent>
<cfset Variables.Datasource = "xxx">
<cffunction name="Save" access="remote">
<cfset var local = {}>
<!--- todo: try/catch --->
<cfif arguments.PersonID>
<cfquery datasource="#Variables.Datasource#">
UPDATE Person
SET FirstName = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.FirstName#">
,LastName = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.LastName#">
WHERE PersonID = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.PersonID#">
</cfquery>
<cfset local.result = arguments.PersonID>
<cfelse>
<cfquery name="local.qry" datasource="#Variables.Datasource#">
INSERT INTO Person(FirstName,LastName) VALUES(
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.FirstName#">
,<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.LastName#">
);
SELECT PersonID FROM Person
WHERE PersonID=Scope_Identity()
</cfquery>
<cfset local.result = local.qry.PersonID>
</cfif>
<cfreturn local.result>
</cffunction>
</cfcomponent>
I need to pass in form.PersonID, form.firstname, form.lastname.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的远程函数可以接受一个结构体参数或 3 个字符串参数(PersonID、名字和姓氏)。
请参阅文档中的
Your remote function can accept either a struct argument, or 3 string arguments (PersonID, firstname and lastname).
See
<CFARGUMENT>
in documentation一件不相干的事。在 cf9 中,您已经有 local 结构在等待。有关此内容的更多信息,请参见http:// forta.com/blog/index.cfm/2009/6/21/The-New-ColdFusion-LOCAL-Scope
One unrelated thing. In cf9 you already have the local struct waiting. More on this here http://forta.com/blog/index.cfm/2009/6/21/The-New-ColdFusion-LOCAL-Scope