开发者

Passing the form scope to a Remote cfc

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.


Your remote function can accept either a struct argument, or 3 string arguments (PersonID, firstname and lastname).

See <CFARGUMENT> in documentation


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜