本文介绍了何时何时不在ColdFusion中使用hash#符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中使用符号围绕每个动态值,并在我的一些代码在这里发布帮助,我被告知没有必要使用在许多地方例如< cfif> 语句。

I use the # symbol around every dynamic value in my application and after posting some of my code on here for help, I've been told there's no need to use the # in many places e.g. <cfif> statements.

所以我开始删除#符号,直到我意识到我打破了我的应用程序,因为我从 value =标签

So I have started removing the # symbols, until I realised I broke my application because I removed the # symbols from the value="" attribute of a <cfprocparam> tag.

我感到困惑的是:< cfprocparam> / p>

I am confused as to:


  1. 为什么使用符号是一些地方而不是其他地方 和< ;

  1. Why use the # symbol is some places and not others (and what is the benefit of not using it?)
  2. Why if they are not required in <cfif> and <cfargument> tags are they suddenly required in <cfprocparam> tags?
  3. Due to this lack of consistency, is it not better to just wrap hashes around every dynamic value in the first place?


推荐答案

没有不一致(或非常小:没有你所引用的是不一致),它只是你不理解规则(这是真的很基本)。这些都在文档中:

There is no inconsistency (or very little: none of what you cite are inconsistencies), it's just you not understanding the rules (which are pretty basic really). It's all in the docs: "Using number signs"

简而言之,在CFML语句中,所有元素都被视为CFML,因此不需要特别标记它们。 EG:

In short, within a CFML statement, all elements are considered CFML, so there is no need to specifically mark them as such. EG:

<cfset myVar = someFunction(anArgument)>

没有歧义, myVar someFunction anArgument 是CFML结构以外的任何东西,因此不需要这样做:

There is no ambiguity there that myVar, someFunction and anArgument are anything other than CFML constructs, so no need to do this sort of thing:

<cfset myVar = #someFunction(anArgument)#>

有些人倾向于做。

在文本中间或字符串中,对于什么是文本和什么是CFML有歧义,所以需要使用井号来标记它们。 EG:

In the middle of text or within a string, there is ambiguity as to what's text and what's CFML, so one needs to use pound signs to mark them as such. EG:

<cfset myVar = "The time is #now()#">

有必要用我们的符号来消除 now code>作为CFML语句,而不仅仅是字符串的一部分,例如:

It's necessary to us pound-signs there to disambiguate now() as being a CFML statement, an not just part of the string, eg:

<cfset myVar = "CFML has a function now() which returns the current timestamp">

等于:

<cfquery>
    SELECT col1
    FROM table2
    WHERE col2 = #someValue#
</cfquery>

没有办法知道 someValue 是一个变量,没有标记为这样。

There would be no way of knowing someValue is a variable there without marking it as such.

基本上就是这样。这不复杂。

That's basically it. It's not complicated.

这篇关于何时何时不在ColdFusion中使用hash#符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 10:40