2011-07-27 72 views
4

<cfexit>在一個函數裏面,在一個cfc裏面做什麼?CFEXIT在CFC的函數中做什麼?

是否與<cfabort>一樣?

我重構一些舊代碼,並想知道如果我需要特別注意它...

感謝。

回答

8

我怎麼一個基本<cfexit>的行爲的回憶是:

  1. 一個CFC內使用,cfexit退出CFC功能。但是 繼續處理調用頁面。
  2. 如果在一個函數內,但不在一個cfc內,則處理被中止。

更新: 我剛剛確認CF9.0.1

結果(使用cfexit)

Start calling page 
Called test() 
Finish calling page 
Called on requestEnd 

結果(使用cfabort)根據該行爲

Start calling page 
Called test() 
Called on requestEnd 

Test.cfm

Start calling page <br /> 
<cfset createObject("component", "Foo").test()> 
Finish calling page <br /> 

Foo.cfc

<cfcomponent> 
    <cffunction name="test" output="true"> 
     Called test()<br /> 
     <cfexit> 
    </cffunction> 
</cfcomponent> 
+1

好了,所以它的行爲就像''如果'returntype'不是'void',它會拋出異常。 – Henry

+0

..或返回類型'string'。 – Leigh

+1

只需使用返回。很好的問題。傻標籤:) –