;中国 COLD FUSION 用户组; WWW.CFWINDOW.COM 
您的位置 :首页 >> CF 技巧文章 >> 阅读文章内容 [ 关闭窗口 ]      

技巧文章内容 
    如何用户个人定义的函数
文章作者 : Kakusoo [ linkfoxo@yahoo.com ]          Web URL : http://
上载日期 : 2000-11-21

The Situtation: You want to create your own functions to use across several CF pages

The Solution: We're all anxiously awaiting the debut of true UDFs. Until then, the best we can do is to create custom tags that can be used like functions. Never created a custom tag before? Don't worry -- it's the soul of simplicity. Let's create one now that produces management decisions. This is useful when you don't have a manager around to help you. We'll save it as "InstaMgr.cfm".

First, we'll create a new ColdFusion page that does what we want.



<!--- Create the universe of answers. --->

<cfset answer1 = "Hmmm...better let me think about it.">

<cfset answer2 = "Sorry, HQ put the kabosh on all new spending.">

<cfset answer3 = "Sounds like a personal problem.">



<!--- All parameters passed to the custom tag/function are referred to with an 

"attributes." prefix once within the scope of the tag. --->



<!--- ...to a manager all questions sound the same... --->

<cfset attributes.theQuestion = "Blah blah yadda yadda ho hum">



<!--- Select one... --->

<cfset num = RandRange(1,3)>



<!--- Return the answer to the caller. BTW, "caller." is the way you 

return info from a custom tag to the file that called it.--->

<cfoutput>

 <cfset caller.InstaMgr = "#Evaluate('answer' & num)#">

</cfoutput>



That's all there is to creating a custom tag. You can call it either with a <cf_ prefix (like <cf_InstaMgr>) or with a CFMODULE tag. For example

<cf_InstaMgr theQuestion = "Can we get some more resources on the mission critical project that must be done by next week?">








< 联系我们 --- 中国Cold Fusion用户组>

CFUG 国内(总部):Linkfoxo    上海:CFANS    北京:Cafe,Cyberkid,liwater    沈阳:Wangking
  
哈尔滨:Baiming    浙江:梅盛松    江西:陈末
  
CFUG (国际) Nagoya(名古屋):Codeguru    新加坡:YUZI    新西兰(Auckland):Richard CHEN
Copyright 2000-2001 www.cfwindow.com.All rights reserved

;中国 COLD FUSION 用户组; WWW.CFWINDOW.COM