Utility Function: RequireScript()
- November 1, 2008 5:30 AM
- ColdFusion, Utility Function
- Comments (0)
I'm not too happy with with this implementation, but I think it works out fairly well. Note that it uses the two functions in the related posts.
<cffunction name="RequireScript" access="public" output="false" returntype="void">
<cfargument name="script" type="string" required="true" />
<cfif NOT StructKeyExists(request, "__requirescript")>
<cfset request["__requirescript"] = ArrayNew(1) />
</cfif>
<cfif NOT ArrayFind(request["__requirescript"], arguments.script)>
<cfset ArrayAppend(request["__requirescript"], arguments.script) />
<cfset IncludeScript(arguments.script) />
</cfif>
<cfreturn />
</cffunction>
<cfargument name="script" type="string" required="true" />
<cfif NOT StructKeyExists(request, "__requirescript")>
<cfset request["__requirescript"] = ArrayNew(1) />
</cfif>
<cfif NOT ArrayFind(request["__requirescript"], arguments.script)>
<cfset ArrayAppend(request["__requirescript"], arguments.script) />
<cfset IncludeScript(arguments.script) />
</cfif>
<cfreturn />
</cffunction>