此 ColdFusion 声明中的 # 有何含义?

发布于 2024-11-18 16:16:54 字数 217 浏览 1 评论 0原文

我试图更好地理解冷融合只是为了解决一个小问题。但我一生都找不到这意味着什么,

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

箜明 2024-11-25 16:16:54

你所拥有的是一个写得不好的代码块。

为了回答你的问题,哈希值内的任何内容都是 ColdFusion 变量。当您打算输出值时,需要使用哈希值。

您发布的此声明的问题在于,开发人员让您假设Manufacturer_name 是ManufacturerList 查询的一部分,这可能是安全的假设,但却是一种糟糕的编码实践。您应该始终限制所有变量的范围,原因有两个:

  1. 可读性和可维护性。如果他们这样做了,您可能就不必在这里发布问题了。
  2. 确定变量的作用域意味着 ColdFusion 不必遍历各个作用域来找出该变量所在的作用域。这会提高应用程序的性能。对于某些范围,不限制对变量的调用将意味着您的代码将无法找到它。此处的查询变量并非如此,但对于其他结构内的变量来说会发生这种情况。

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:

  1. Readability and maintainability. Had they done this you probably would not have had to post a question here.
  2. Scoping variables means that ColdFusion does not have to traverse the various scopes out there to figure out what scope this variable lives in. This leads to performance gains in your application. With some scopes, not scoping the call to the variable would mean that your code would fail to find it. Not so with query variables here, but for variables inside other structures that would happen.
谜兔 2024-11-25 16:16:54

#manufacturer_name# 表示运行查询时将生成该值。在您的查询中,您可能有一个名为“manufacturer_name”的字段。

通过将制造商名称放在 # 符号中,意味着该字段将填充您查询中的值。

这是一个例子:

<cfquery name="qEmployee" datasource="cfdocexamples">  
 SELECT Emp_ID, FirstName, LastName, Salary FROM EMPLOYEE  
</cfquery>  
      <table bgcolor="CadetBlue" cellpadding="0" cellspacing="0">  
     <tr bgcolor="DarkCyan">  
         <td><b>Emp ID</b></td>  
         <td><b>First Name</b></td>  
         <td><b>Last Name</b></td>  
         <td><b>Salary</b></td>  
        </tr>  
     <cfoutput query="qEmployee">  
            <tr>  
                <td>#Emp_ID#</td>  
                <td>#FirstName#</td>  
                <td>#LastName#</td>  
                <td>#Salary#</td>  
            </tr>  
        </cfoutput>  
    </table>  

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:

<cfquery name="qEmployee" datasource="cfdocexamples">  
 SELECT Emp_ID, FirstName, LastName, Salary FROM EMPLOYEE  
</cfquery>  
      <table bgcolor="CadetBlue" cellpadding="0" cellspacing="0">  
     <tr bgcolor="DarkCyan">  
         <td><b>Emp ID</b></td>  
         <td><b>First Name</b></td>  
         <td><b>Last Name</b></td>  
         <td><b>Salary</b></td>  
        </tr>  
     <cfoutput query="qEmployee">  
            <tr>  
                <td>#Emp_ID#</td>  
                <td>#FirstName#</td>  
                <td>#LastName#</td>  
                <td>#Salary#</td>  
            </tr>  
        </cfoutput>  
    </table>  
ゞ花落谁相伴 2024-11-25 16:16:54

# 符号中包含的字符串确实表示变量,在本例中,它指的是查询“manufacurelist”中的列名称

string enclosed in # symbols do denote variables, in this case this is referring to a column name in the query "manufacurelist"

无人问我粥可暖 2024-11-25 16:16:54

此外,最佳实践是将查询名称添加到该查询的任何列上(事实上,对所有变量都执行此操作,将它们放在适当的范围内)。

除了使您的代码更加高效之外,从长远来看,当您尝试找出特定变量的来源时,它还可以使开发人员的工作更加轻松。

例如这样做:

<cfoutput query="manufactureList">#manufactureList.manufacturer_name#</cfoutput>

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:

<cfoutput query="manufactureList">#manufactureList.manufacturer_name#</cfoutput>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文