5

我正在编写我的第一个 ColdFusion 组件,但出现此错误。有谁知道这意味着什么?

Invalid CFML construct found on line 2 at column 1.
ColdFusion was looking at the following text:
<
The CFML compiler was processing:
< marks the beginning of a ColdFusion tag.Did you mean LT or LTE?
The error occurred in C:/inetpub/wwwroot/ColdFusion/test.cfm
<cfcomponent displayname="News" hint="Get News">
<cffunction name="GetNews" returntype="query">
<cfquery datasource="CFDatabase" name="myQuery"

源代码:

<cfcomponent displayname="News" hint="Get News">
<cffunction name="GetNews" returntype="query">
    <cfquery datasource="CFDatabase" name="myQuery">
        select * from tbNews
    </cfquery>
    <cfreturn myQuery>
</cffunction>
</cfcomponent>

<cfinvoke component="components.News" method="GetNews" returnvariable="AllNews">

<table width="100%">
<cfoutput query="AllNews">
<tr>
    <td>Title:</td>
    <td><cfoutput>#myQuery.Title#</cfoutput></td>
    <td>Body:</td>
    <td><cfoutput>#myQuery.Description#</cfoutput></td>
</tr>
</cfoutput>
</table>
4

3 回答 3

9

您已将其放置<cfcomponent>在 cfm 文件中,这是我不允许的。

<cfcomponent>块移动到扩展名为 .cfc 的文件(例如 News.cfc),然后从 .cfm 文件中调用它

在新闻.cfc

<cfcomponent>
<cffunction name="getNews">
...
</cffunction>
</cfcomponent>

在 test.cfm

<cfset newsObj = createobject('component', 'News')>
<cfset AllNews = newsObj.getNews()>
于 2012-11-13T10:35:58.443 回答
2

错误出现在一个名为 test.cfm 的文件中,而您正在向我们展示 CFC 中的代码,这并没有多大帮助。

但是,错误消息相当清楚:您<在错误的地方使用了 a 。它位于 test.cfm 的第 2 行(或者可能来自第 1 行的某些东西的连锁反应)。

您可以更新您的问题以发布它正在谈论的实际代码吗?

但请查看第 1-2 行并查找语法错误。是否有一个表达式,您正在执行小于评估,并且您使用 < 而不是 LT / LTE(根据错误消息中的指导...)

于 2012-11-13T10:27:01.080 回答
0

我遇到了同样的错误,我发现我的一个标签>末尾缺少一个(大于号)cf,恰好是一个<cfif>. 所以,我改变了

<cfif condition EQ true</cfif>

<cfif condition EQ true></cfif>

#另一次,我在HTML 元素的样式属性中遇到了类似的问题。由于它在 a 中cfoutput,ColdFusion 尝试将我的意思作为十六进制颜色值(以主题标签开头)呈现为 ColdFusion 变量,但它没有用第二个主题标签关闭。所以我将内联样式更改为外部样式表,老实说,我一开始就应该这样做:)

于 2020-01-14T01:10:41.953 回答