我可以将结构存储在 Coldfusion 会话变量中吗?
我正在将一个结构传递给 CF 自定义标签。我希望 CFM 页面是这个自定义标记,将此结构分配给动态创建的会话变量。创建会话变量在将其分配给简单值(例如数字)时有效,但在按照我下面的方式将其分配给结构体时失败。
<cfset Evaluate("SESSION.myVar#ATTRIBUTES.count# = #ATTRIBUTES.myStruct#")>
我认为这是可能的,但是当我尝试这样做时出现错误: 复杂的对象类型无法转换为简单的值。
这就是结构体的创建方式:
<cfset testStruct = StructNew()>
<cfset testStruct.something = 2>
并通过自定义标记传递:
<cf_myTag myStruct="#testStruct#" count="#i#">
我认为评估部分把事情弄乱了。
I'm passing a struct to a CF Custom Tag. I'd like the CFM page that is this custom tag to assign this struct to a dynamically created session variable. Creating the session variable works when assigning it to a simple value such as a number, but fails when assigning it to the struct in the way I'm doing it below.
<cfset Evaluate("SESSION.myVar#ATTRIBUTES.count# = #ATTRIBUTES.myStruct#")>
I thought this was possible, but when I try to do so I get an error:
Complex object types cannot be converted to simple values.
This is how the struct is created:
<cfset testStruct = StructNew()>
<cfset testStruct.something = 2>
And passed through the custom tag:
<cf_myTag myStruct="#testStruct#" count="#i#">
I think the Evaluate portion is messing things up here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
正如 Leigh 所说,使用数组表示法而不是 Evaluate() 来创建动态命名的会话变量:
As Leigh says, use array notation rather than Evaluate() to create your dynamically named session variable:
是的,可以,
只需使用重复方法
Yes you can,
Just use the duplicate method
是的,您可以执行以下操作:
请注意,我在这里使用 cflock 以避免任何潜在的竞争条件。
yes, you can just do the following:
note I'm using a cflock here to avoid any potential race conditions.
上面的问题是评估语句。它尝试将结构评估为字符串中的简单值,然后评估字符串。
您可以完全绕过评估。原因是您想要一个动态命名的会话变量?
The issue above is the evaluate statement. It's trying to evaulate the structure as a simple value in the string, and then evaluate the string.
You can get around evaulate entirely. The reason is you want a dynamically named session variable?