【问题标题】:Coldfusion Components:- The argument passed to the function is not of type numericColdfusion 组件:- 传递给函数的参数不是数字类型
【发布时间】:2014-01-01 03:55:51
【问题描述】:

我有一个简单的表格

form.cfm:-

 <cfset Registr = createObject("component", "forms.Registr") /> 
 <cfset setFoo = createObject('component','forms.Registr).putNUsr(username,password,rating) />

    <form name="regFrm"  action="#cgi.script_name#" method="post" onsubmit="submitform();" >
      <tr><td>Username:</td>

    <td><input  type="text" name=" Username" value="#form. Username#" ></td></tr>


        <tr><td>Password:</td>
    <td><input class="" type="password" name="password" value="#form.password#" ></td></tr>     

        <tr><td>Rate:</td>

                <select name="rating" >
                    <option value="" ></option>
                    <cfloop query="qGetReting">
                        <option value="#rating_id#" <cfif form. rating eq prof_id>selected</cfif> >#rating#</option>
                    </cfloop>
                </select>
            </td>
        </tr>
    </form>

现在“forms”文件夹中有一个名为 Registr.cfc 的 cfc,它有一个名为 'putNUsr' 的插入函数,'Registr.cfc' 的代码如下。

<cfcomponent>
<cffunction name="putNUsr" returntype="void" displayname="" output="no">
        <cfargument name="password" type="string" required="true">
        <cfargument name="rating" type="numeric" required="true">        
        <cfargument name="username" type="string" required="true">    
            <cfquery datasource="#application.xyz#" name="q_putNUsr">
                insert into 
           users (username
                , password
                , rating)

                 values(                

            <cfqueryparam value="#arguments. username#" cfsqltype="CF_SQL_VARCHAR" />,          
            <cfqueryparam value="#arguments.password#" cfsqltype="CF_SQL_VARCHAR" />,
            <cfqueryparam value="#arguments.rating#" cfsqltype="CF_SQL_INTEGER"  )

                    </cfquery>
</cffunction>
 </cfcomponent>

如果我不使用表单字段“rating”,我可以用数据填充数据库 是数字。 否则我收到如下错误:-

The RATING argument passed to the putNUsr function is not of type numeric. 
If the component name is specified as a type of this argument, it is possible that either a definition file for the component cannot be found or is not accessible.

请 帮助 -S 瓦利

【问题讨论】:

    标签: coldfusion components


    【解决方案1】:

    您已将函数中参数的顺序定义为密码、评级、用户名,但您以用户名、密码、评级的顺序传递它们。

    您确实可以选择使用 ColdFusion 将参数作为命名参数传递,例如 putNUsr(username = 'me', password = 'letmein', rating = 5)。当你这样做时,你可以按任何顺序传递它们

    【讨论】:

    • 你也可以这样做:
    【解决方案2】:

    Gary 已经发现了你的错误。关于评级的另一件事是你可以将它包装在 Val() 函数中,它会给你一个空字符串 0...

    【讨论】:

      【解决方案3】:

      您的评级选择的默认(第一个)选项项将一个空字符串传递给 putNUsr 组件。空字符串不是数字,因此无法通过类型验证。

      您必须在 putNUsr 组件中添加一些额外的逻辑来解决这个问题,或者只需将表单中的默认评级选项设置为 0(例如)。

      【讨论】:

        【解决方案4】:

        我在代码中发现了同样的问题。当我用“PasswordVal”等其他名称替换参数“Password”时,它已解决。出于某种原因,Coldfusion 不会读取名为“密码”的参数并引发错误。如果您将 Password 的名称更改为其他名称,则代码将开始工作。

        【讨论】:

        • 如果是这种情况(我没有测试过),那就是另一个问题了。最初的问题是由于以错误的顺序传递参数,即在期望数字时传递字符串。
        猜你喜欢
        • 1970-01-01
        • 2018-03-26
        • 2023-03-31
        • 2017-05-10
        • 1970-01-01
        • 1970-01-01
        • 2012-08-25
        • 2018-06-28
        • 2014-07-18
        相关资源
        最近更新 更多