此 ColdFusion 声明中的 # 有何含义?
我试图更好地理解冷融合只是为了解决一个小问题。但我一生都找不到这意味着什么,
<cfoutput query="manufactureList">#manufacturer_name#</cfoutput>
我知道这是引用一个名为 manfatureList 的查询,但是 #manufacturer_name# 是一个变量吗?
I am trying to understand coldfusion better just to solve a minor problem. But for the life of me I cannot find what this means
<cfoutput query="manufactureList">#manufacturer_name#</cfoutput>
I know this is referencing a query named manfatureList, but was is #manufacturer_name# is that a variable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你所拥有的是一个写得不好的代码块。
为了回答你的问题,哈希值内的任何内容都是 ColdFusion 变量。当您打算输出值时,需要使用哈希值。
您发布的此声明的问题在于,开发人员让您假设Manufacturer_name 是ManufacturerList 查询的一部分,这可能是安全的假设,但却是一种糟糕的编码实践。您应该始终限制所有变量的范围,原因有两个:
What you have is a poorly written code block.
To answer your question, anything inside the hashes is a ColdFusion variable. You need to use the hashes when you intend to output the value.
The problem with this statement you posted is that the developer left you to assume that manufacturer_name is part of the manufactureList query, which might be safe to assume but a terrible coding practice. You should always scope all variables for two reasons:
#manufacturer_name# 表示运行查询时将生成该值。在您的查询中,您可能有一个名为“manufacturer_name”的字段。
通过将制造商名称放在 # 符号中,意味着该字段将填充您查询中的值。
这是一个例子:
The #manufacturer_name# means that the value will be generated when the query is run. In your query you probably have a field called manufacturer_name.
By placing the manufacturer_name in the # sign it means that this field will be populated with the value from your query.
Here is an example:
# 符号中包含的字符串确实表示变量,在本例中,它指的是查询“manufacurelist”中的列名称
string enclosed in # symbols do denote variables, in this case this is referring to a column name in the query "manufacurelist"
此外,最佳实践是将查询名称添加到该查询的任何列上(事实上,对所有变量都执行此操作,将它们放在适当的范围内)。
除了使您的代码更加高效之外,从长远来看,当您尝试找出特定变量的来源时,它还可以使开发人员的工作更加轻松。
例如这样做:
Also, it's best practice to prepend the query name onto any columns from that query (and in fact do this with all variables, put them in their appropriate scope).
As well as making your code more efficient, it also makes life easier for the developer in the long run when you're trying to work out where a particular variable came from.
e.g. do this instead: