Search code examples
coldfusioncoldfusion-10coldfusion-11

How to run a cfquery within the onRequestStart() function?


I want to run a query on every page that a user requests. This query is needed to get back preferences set by the user's organisation for the application. This is what I have tried:

<cffunction name="onRequestStart" access="public" returntype="boolean">
  <cfargument type="String" name="TargetPage" required="true"/> 
<cfquery name="rsSettings">
SELECT *
FROM
dbo.Settings
</cfquery>
<cfreturn true>
</cffunction>
</component>

However each pages that looks for the rsSettings recordset says that its not defined. If I put the same query within each page that needs it then it works fine.

Does onRequestStart() not handle cfquery?


Solution

  • <cfquery name="request.rsSettings">
        SELECT *
        FROM
        dbo.Settings
    </cfquery>
    

    Then in the page use:

     request.rsSettings.columName