On 3/10/06, Hamoud, Ryan N. <[EMAIL PROTECTED]> wrote:
> So is not possible to accomplish this with a CFC? When i did this with my
> custom tage
> i was able to access allmy constants on any page as
> follows.....example <cfset tablename = #C_LV#> I would still like to be
> able to do this.
CFCs aren't custom tags. The link that Charlie sent was (I assume)
intended to prompt you to do some reading up on how CFCs work. At a
very high level, you call a method in a CFC, that method does some
sort of work presumably, and then the CFC method returns something
(can be anything you want, or nothing at all) to the thing that called
it. In your case your function could stay largely the same, you'd
just want to create a single value that could be returned by the
function; looks like a struct would work in your case. So this:
<CFFUNCTION NAME="createCoreConstants" access="remote" returntype="void">
<CFARGUMENT NAME="tablename" type="string" required="yes">
<cfquery name="coreLV" datasource="#request.app.DSN#"
blockfactor="10" cachedwithin="#request.app.queryCache30#">
SELECT
dbo.#ARGUMENTS.tableName#.legalValue,
dbo.#ARGUMENTS.tableName#.lKey
FROM dbo.#ARGUMENTS.tableName#
where dbo.#ARGUMENTS.tableName#.isActive=1
</cfquery>
<cfoutput query="coreLV">
<cfset "CALLER.C_#listchangedelims(
listchangedelims(listchangedelims(coreLV.legalValue,'_','-'),'_','
'),'_','/')#" = coreLV.lKey>
</cfoutput>
</CFFUNCTION>
Would become something like this:
<CFFUNCTION NAME="createCoreConstants" access="remote" returntype="struct">
<CFARGUMENT NAME="tablename" type="string" required="yes">
<cfargument name="dsn" type="string" required="true" />
<cfargument name="cacheTime" type="numeric" required="true" />
<cfset var constants = StructNew() />
<cfset var coreLV = "" />
<cfquery name="coreLV" datasource="#arguments.dsn#"
blockfactor="10" cachedwithin="#arguments.cacheTime#">
SELECT
dbo.#ARGUMENTS.tableName#.legalValue,
dbo.#ARGUMENTS.tableName#.lKey
FROM dbo.#ARGUMENTS.tableName#
where dbo.#ARGUMENTS.tableName#.isActive=1
</cfquery>
<cfoutput query="coreLV">
<cfset constants["C_#listchangedelims(
listchangedelims(listchangedelims(coreLV.legalValue,'_','-'),'_','
'),'_','/')#"] = coreLV.lKey>
</cfoutput>
<cfreturn constants />
</CFFUNCTION>
Things to note:
* Return type of the function is struct
* Pass in the dsn and cache time so your CFC doesn't use the request scope
* var scope everything inside your functions for thread safety!
* The constants are all put into a single struct, then this struct is returned
So the code that calls this would be something along these lines:
<cfset myCFC = CreateObject("component", "MyCFC") />
<cfset constants = myCFC.createCoreConstants() />
At that point the constants variable will have all your constants in
it. I didn't test this obviously since I don't have your data, etc.
but the principles should work.
Hope that helps,
Matt
--
Matt Woodward
[EMAIL PROTECTED]
http://www.mattwoodward.com
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to
[email protected] with the words 'unsubscribe cfcdev' as the subject of the
email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting
(www.cfxhosting.com).
An archive of the CFCDev list is available at
www.mail-archive.com/[email protected]