Adobe ColdFusion 8

cfexit

描述

这个标签应用于中止当前运行的 CFML 自定义标签,退出在当前运行的CFML自定义标签,或者重新处理当前运行的CFML自定义标签的一段代码。

语法

<cfexit 
    method = "method">

注: 你可以在attributeCollection 中指定这个标签的属性,作为一个结构的value,在attributeCollection 中指定结构的名称,并使用这个标签的属性名称作为这个结构的Keys.

属性

属性

必选/可选

默认

描述

method

可选

exitTag

  • exitTag: 中止当前运行的标签。
  • exitTemplate: 退出在当前运行的CFML自定义标签。
  • loop: 重新处理当前运行的CFML自定义标签的一段代码。

用途

如果这个标签使用在自定义标签的外部分,比如说在一个基本程序页面或者一个include页面里,用法和cfabort标签一样。cfexit标签可以简化在自定义标签里错误的检查和验证逻辑。

cfexit标签函数依据它所在位置和运行的代码程序有不同的情况。

方法属性

调用cfexit的位置

动作

exitTag

 

 

基本页面

终止处理

运行模式=开始

继续后结束标记

运行模式=结束

继续后结束标记

exitTemplate

 

 

基本页面

终止处理

处理模式=开始

从body内第一个子程序开始继续运行

处理模式=开始

继续后结束标记

loop

基本页面

错误

 

处理模式=开始

错误

 

处理模式=开始

从body内第一个子程序开始继续运行

范例

<h3>cfexit Example</h3>
<p>cfexit can be used to abort the processing of the currently executing CFML custom tag. Execution resumes following the invocation of the custom tag in the page that called the tag.
<h3>Usage of cfexit</h3>
<p>cfexit is used primarily to perform a conditional stop of processing inside a custom tag. cfexit returns control to the page that called that custom tag, or in the case of a tag called by another tag, to the calling tag.</p>

<!--- cfexit can be used within a CFML custom tag, as follows: --->
<!--- Place this code (uncomment the appropriate sections) within the customtags directory. --->

<!--- MyCustomTag.cfm --->
<!--- This simple custom tag checks for the existence of myValue1 and myValue2. If they are both defined, the tag adds them and returns the result to the calling page in the variable "result". If either or both of the expected attribute variables is not present, an error message is generated, and cfexit returns control to the calling page. --->

<!--- <cfif NOT IsDefined("attributes.myValue2")>
            <cfset caller.result = "Value2 is not defined">
            <cfexit method = "exitTag">
     <cfelseif NOT IsDefined("attributes.myValue1")>
            <cfset caller.result = "Value1 is not defined">
            <cfexit method = "exitTag">
     <cfelse>
             <cfset value1 = attributes.myValue1>
             <cfset value2 = attributes.myValue2>
            <cfset caller.result = value1 + value2>
     </cfif> --->
<!--- End MyCustomTag.cfm --->

<!--- Place this code within your page --->     

<!--- <p>The call to the custom tag, and then the result: </p>
<CF_myCustomTag
        myvalue2 = 4>
<cfoutput>#result#</cfoutput> --->
<p>If cfexit is used outside a custom tag, it functions like a cfabort. For example, the text after this message is not processed:</p>
<cfexit>
<p>This text is not executed because of the cfexit tag above it.</p>