blank
blank

Reputation: 18170

Why can't my coldfusion cfc access a udf included in application.cfm?

I've got a logging function (can't use cflog) included in application.cfm and my .cfm pages can access this, but any components I use give me a "Variable LOGGER is undefined." error.

application.cfm

<cfinclude template="logging.cfm">

logging.cfm

<cffunction name="logger" >
 ...
</cffunction>

Any ideas as to what I'm doing wrong?

Upvotes: 1

Views: 777

Answers (1)

marc esher
marc esher

Reputation: 4921

because the way components work is that a component can't see the "variables" scope outside of itself, and when you <cfinclude> your logging.cfm, it's including those functions into the page's variable scope. in order for your component to call those functions, you might do this:

<cfinclude template="logging.cfm">

<cfset request.logger = variables.logger>

and then in your <cfcomponent>, you could call request.logger(whatever).

But honestly, this feels backwards to me. Instead, why not a Logger.cfc that contains a function named "log", and then when you want to log something, you just do:

<cfinvoke component="my.Logger" method="log" message="#mylogmessage#">

Upvotes: 10

Related Questions