如何在不使用cfinvoke的情况下在CFC上运行静态方法?

时间:2010-01-15 18:37:21

标签: coldfusion cfc

如何在不使用cfinvoke的情况下在CFC上调用静态方法?我知道我可以这样做:

<cfinvoke component="MyComponent" method="myStaticMethod' arg1="blah" returnvariable=myReturnVar>

我希望能够以与UDF相同的方式调用此方法:

<cfset myReturnVar = MyComponent.myStaticMethod(blah)>

然而,这不起作用。是否有语法,我搞砸了或者这是不可能的?

2 个答案:

答案 0 :(得分:5)

不可能,因为ColdFusion中没有“静态方法”。

您问题中的<cfinvoke>行与以下内容相同:

myReturnVar = CreateObject("component", "MyComponent").myStaticMethod(arg1="blah");

答案 1 :(得分:3)

您需要先创建对象。

<cfset MyComponent = createObject("component","MyComponent") />
<cfset myReturnVar = MyComponent.myMethod(blah) />
相关问题