我正在编写我的第一个 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>
您已将<cfcomponent>
放在 cfm 文件中,这是我不允许的。
将<cfcomponent>
块移动到扩展名为 .cfc 的文件(例如 News.cfc),然后从.cfm文件中调用它
in 新闻网
<cfcomponent>
<cffunction name="getNews">
...
</cffunction>
</cfcomponent>
测试中.cfm
<cfset newsObj = createobject('component', 'News')>
<cfset AllNews = newsObj.getNews()>
错误在一个名为 test.cfm 的文件中,您向我们展示了 CFC 中的代码,这没有多大帮助。
但是,错误消息相当明确:您在错误的位置使用了<
。 它位于测试的第 2 行.cfm(或者可能是第 1 行某些内容的连锁反应)。
你能更新你的问题以发布它正在谈论的实际代码吗?
但是查看第 1-2 行并查找语法错误。 是否有一个表达式,您正在执行小于评估,并且您正在使用
我遇到了同样的错误,我发现我的一个cf
标签末尾缺少一个>
(大于号),这恰好是一个<cfif>
。所以,我改变了
<cfif condition EQ true</cfif>
自
<cfif condition EQ true></cfif>
还有一次,我在 HTML 元素的样式属性中遇到了类似的#
问题。由于它是在cfoutput
中,ColdFusion试图将我的意思是十六进制颜色值(以主题标签开头)呈现为ColdFusion变量,但它没有用第二个主题标签关闭。所以我将内联样式更改为外部样式表,老实说,我应该首先这样做:)