2011-12-20 34 views
0

我正在使用ColdFusion 9.1.2。我是否需要致電擴展CFC或父CFC?

我有一個名爲orders.cfm的CFC。這是「父母」CFC。

我有另一個CFC調用orderswrapup.cfc。這是orders.cfc的擴展。在orderswrapup.cfc,我有這條線在頂部:

<cfcomponent extends="orders"> 

眼下,這不起作用:

objOrders = createObject("component", "orders"); 
MyResult = objOrders .someMethodActuallyInOrdersWrapUpCFC(); 

但這並工作:

objOrders = createObject("component", "orderswrapup"); 
MyResult = objOrders .someMethodActuallyInOrdersWrapUpCFC(); 

要訪問orderswrapup.cfc中的方法,我可以像調用orders.cfc中的方法那樣調用方法,還是需要直接調用它?看來我應該能夠打電話給家長,而不是孩子。

回答

7

當您創建新的orderswrapup對象時,orderswrapup可以訪問所有訂單的功能,因爲orderswrapup是訂單的孩子。

當您將orderswrapup.cfc定義爲<cfcomponent extends="orders">時,您將orderswrapup.cfc定義爲繼承所有orders.cfc的函數。這允許您通過orderswrapup.cfc調用orders.cfc中的任何函數,就好像它們是orders.cfc中的函數一樣。但是orders.cfc與orderswrapup.cfc沒有定義的關係,所以它不能調用orderswrapup.cfc

一些好的writeups的內部功能 - http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=buildingComponents_30.html

+0

感謝您的解釋! – 2012-01-17 15:31:32

0

擴展的氟氯化碳昂貴...

如果你發現自己需要進行3級以上的延伸,你會注意到性能受到影響。