为什么没有定义参数,如果我可以转储它,它在Coldfusion有一个值? [英] Why a parameter is not defined, if I can dump it and it has a value in Coldfusion?
问题描述
只是有点无知...使用Coldfusion8,如果我转储我的会话到文件:
< cfdump output = D:\ColdFusion8\logs\dump.txtvar =#Session#>
这包括:
accounttyp:whatever
如果我只转储这个参数,
< cfdump output =D:\ColdFusion8\logs\dump.txtvar =#Session。 accounttyp#>
问题:
如果定义并转储可以检查 isDefined :
< cfdump output =D: \\ColdFusion8\logs\dump.txtvar =#IsDefined(Session.accounttyp)#>
原来是否?如果它在那里应该定义,应该不是吗?
感谢您的澄清。
< cfdump output =D:\ColdFusion8\logs\dump.txt
var =#IsDefined (Session.accounttyp)#>
这是因为语法不正确。 IsDefined
期望变量的名称,即字符串。通过忽略变量名引号,会话变量首先被计算,其值(whatever)被传递到 IsDefined
。所以代码实际上是检查一个名为whatever,而不是session.accounttyp的变量,即:
< cfif IsDefined (whatever)>
这就是为什么结果是 NO
。这是正确的语法。 (注意引号和缺少磅符号)。
< cfif IsDefined(Session.accounttyp)&但是,我建议切换到 structKeyExists
。通常优先于 IsDefined
,因为它更精确。
Just a little clueless... using Coldfusion8, if I dump my session to file:
<cfdump output="D:\ColdFusion8\logs\dump.txt" var="#Session#">
this includes:
accounttyp: whatever
I get the same result if I only dump this parameter:
<cfdump output="D:\ColdFusion8\logs\dump.txt" var="#Session.accounttyp#">
Question:
If it's defined and dump-able, how come checking isDefined like so:
<cfdump output="D:\ColdFusion8\logs\dump.txt" var="#IsDefined(Session.accounttyp)#">
turns out to be NO? If it's there it should be defined, shouldn't it?
Thanks for some clarification.
解决方案
<cfdump output="D:\ColdFusion8\logs\dump.txt"
var="#IsDefined(Session.accounttyp)#">
It is because the syntax is incorrect. IsDefined
expects the name of a variable ie a string. By omitting the quotes around the variable name, the session variable gets evaluated first, and its value ("whatever") is what gets passed into IsDefined
. So the code is actually checking for a variable named "whatever", not "session.accounttyp" ie:
<cfif IsDefined("whatever")>
That is why the result is NO
. This is the correct syntax. (Notice the quotes and lack of pound signs).
<cfif IsDefined("Session.accounttyp")>
However, I would suggest switching to structKeyExists
. It is generally preferred over IsDefined
because it is more precise.
这篇关于为什么没有定义参数,如果我可以转储它,它在Coldfusion有一个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!