bhinshawnc1
asked on
cffunction setting variables
Trying to modify some code that currently uses a settings.ini file to control the configuration. This won't work in final deployment environment.
Here's the current configuration
<cffunction name="getSettings" access="public" returnType="struct" output="false" hint="Returns application settings as a structure.">
<!--- load the settings from the ini file --->
<cfset var settingsFile = replace(getDirectoryFromPa th(getCurr entTemplat ePath())," \","/","al l") & "/settings.ini">
<cfset var iniData = getProfileSections(setting sFile)>
<cfset var r = structNew()>
<cfset var key = "">
<cfloop index="key" list="#iniData.settings#">
<cfset r[key] = getProfileString(settingsF ile,"setti ngs",key)>
</cfloop>
<cfreturn r>
</cffunction>
settings.ini contains:
[settings]
password=
dsn=
dbtype=sqlserver
fromAddress=
perpage=20
tableprefix=
I want to call the dsn via variables defined in root application.cfm, normally in a query I'd call them like:
<cfquery name="GetSurveys" datasource="#dbname#" username="#dbuser#" password="#dbpw#" >
In the functions, they were originally built like:
<cfquery name="GetSurveys" datasource="#variables.dsn #">
A sample function:
<cffunction name="getSurveys" access="public" returnType="query" output="false" hint="Returns all the surveys.">
<cfargument name="bActiveOnly" type="boolean" required="false" default="false" hint="Restrict to active surveys only. Also does the date restriction.">
<!--- testing <cfargument name="dbname" required="yes" type="string" hint="from root application.cfm"> --->
<cfset var qGetSurveys = "">
<cfset var survey = "">
<cfquery name="qGetSurveys" datasource="#variables.dsn #">
<!--- testing <cfquery name="qGetSurveys" datasource="#dbname#" username="#dbuser#" password="#dbpw#" >--->
select id, name, description, active, datebegin, dateend, resultmailto, surveypassword, thankyoumsg
from #variables.tableprefix#sur veys
<cfif arguments.bActiveOnly>
where active = 1
and (datebegin is null or datebegin < <cfqueryparam value="#now()#" cfsqltype="CF_SQL_TIMESTAM P">)
and (dateend is null or dateend > <cfqueryparam value="#now()#" cfsqltype="CF_SQL_TIMESTAM P">)
</cfif>
</cfquery>
<cfreturn qGetSurveys>
</cffunction>
How do I take the function getsettings and set the variables it returns for DSN to those variables I've already defined in application.cfm for
datasource="#dbname#" username="#dbuser#" password="#dbpw#" so they are passed to the function getsurveys via datasource="#variables.dsn #" ?
Here's the current configuration
<cffunction name="getSettings" access="public" returnType="struct" output="false" hint="Returns application settings as a structure.">
<!--- load the settings from the ini file --->
<cfset var settingsFile = replace(getDirectoryFromPa
<cfset var iniData = getProfileSections(setting
<cfset var r = structNew()>
<cfset var key = "">
<cfloop index="key" list="#iniData.settings#">
<cfset r[key] = getProfileString(settingsF
</cfloop>
<cfreturn r>
</cffunction>
settings.ini contains:
[settings]
password=
dsn=
dbtype=sqlserver
fromAddress=
perpage=20
tableprefix=
I want to call the dsn via variables defined in root application.cfm, normally in a query I'd call them like:
<cfquery name="GetSurveys" datasource="#dbname#" username="#dbuser#" password="#dbpw#" >
In the functions, they were originally built like:
<cfquery name="GetSurveys" datasource="#variables.dsn
A sample function:
<cffunction name="getSurveys" access="public" returnType="query" output="false" hint="Returns all the surveys.">
<cfargument name="bActiveOnly" type="boolean" required="false" default="false" hint="Restrict to active surveys only. Also does the date restriction.">
<!--- testing <cfargument name="dbname" required="yes" type="string" hint="from root application.cfm"> --->
<cfset var qGetSurveys = "">
<cfset var survey = "">
<cfquery name="qGetSurveys" datasource="#variables.dsn
<!--- testing <cfquery name="qGetSurveys" datasource="#dbname#" username="#dbuser#" password="#dbpw#" >--->
select id, name, description, active, datebegin, dateend, resultmailto, surveypassword, thankyoumsg
from #variables.tableprefix#sur
<cfif arguments.bActiveOnly>
where active = 1
and (datebegin is null or datebegin < <cfqueryparam value="#now()#" cfsqltype="CF_SQL_TIMESTAM
and (dateend is null or dateend > <cfqueryparam value="#now()#" cfsqltype="CF_SQL_TIMESTAM
</cfif>
</cfquery>
<cfreturn qGetSurveys>
</cffunction>
How do I take the function getsettings and set the variables it returns for DSN to those variables I've already defined in application.cfm for
datasource="#dbname#" username="#dbuser#" password="#dbpw#" so they are passed to the function getsurveys via datasource="#variables.dsn
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER