在 Coldfusion 组件/CFC 中,我想适当地限定一些变量以供所有包含的函数使用,但要从外部脚本隐藏或阻止。cfc 的内存范围的名称是什么?是“变量”吗?这在包含的函数中可用吗?是否从 cfc 外部阻止?
(CF 8 中的示例)
调用页面:
<cfset settings = structNew()>
<cfset util = createObject("component", "myUtils").init(settings)>
<cfoutput>
#util.myFunction()#
</cfoutput>
myUtils.cfc:
<cfcomponent>
<!--- Need to set some cfc global vars here --->
<cffunction name="init" access="public">
<cfargument name="settings" type="struct" required="no">
<!--- I need to merge arguments.settings to the cfc global vars here --->
<cfreturn this>
</cffunction>
<cffunction name="myFunction" access="public">
<cfset var result = "">
<!--- I need to access the cfc global vars here for init settings --->
<cfreturn result>
</cffunction>
</cfcomponent>
欢迎提供其他最佳实践建议。自从我这样做以来已经有一段时间了。提前致谢。