0

I am a new to ColdFusion. I have Application.cfm and would like to add an onRequestStart function, but it is not working. By not working I mean, when a page calls some application variables (that were set inside `onRequestStart) an error is generated because those variable don't exist.

I can't use Application.cfc. Is there a solution or another way to use onRequestStart with Applciation.cfm?

SOS
  • 6,430
  • 2
  • 11
  • 29
KekoSha
  • 125
  • 13
  • You need to use `application.cfc` – James A Mohler Jan 17 '18 at 14:59
  • are there something like onRequestStart in Application.cfm – KekoSha Jan 17 '18 at 15:09
  • 4
    "I can't use Application.cfc" Why not? Application.cfm already runs on every request, which should be sufficient. So not sure what the issue is ... Can you please post a *small* bit of code - and the error message - so we can better assist? – SOS Jan 17 '18 at 16:08
  • 1
    Thank you Ageax for your comment. [Application.cfm already runs on every request] this statement helped me to understand better the situation and that helped me to write the code. Appreciate your kindness to share and your time. Thank you. – KekoSha Jan 18 '18 at 17:18
  • 1
    @KekoSha - Glad it helped. Hopefully the accepted answer clarifies it more. Although you *could* create an onRequestStart function and use it in your Applciation.cfm ... it's really not needed since any code beneath the `` tag already runs on each request anyway. You didn't mention why you couldn't switch to using an Application.cfc, but I'd strongly recommend it. It's similar to Application.cfm, but a lot more powerful. – SOS Jan 18 '18 at 19:31

3 Answers3

1

So I'm not really sure what your trying to do with the Application.cfm, but like Ageax said, the Application.cfm runs on every request ( whatever workflow you had in mind for the onRequestStart() function you can just do in the Application.cfm)

If you really want an onRequestStart function in Application.cfm you can make your own function and explicitly call it after like this


Application.cfm

<cfset Application.test = " AND IS USING AN Application Var :D!!  ">

<cfscript>

    function onRequestStart(){  
        RETURN "THIS HAPPENS AT THE START OF EVERY REQUEST! #Application.test#";
    }

</cfscript>

<cfoutput> #onRequestStart()#  </cfoutput> 

This question and article might be an intresting read for you if your not forced to use an Application.cfm

ColdFusion: Are there any use cases where an Application.cfm is preferable to an Application.cfc

Migrating from Application.cfm to Application.cfc

Hedge7707
  • 557
  • 1
  • 5
  • 17
1

If you need to using Application.cfm (not sure why this would be a requirement as Application.cfc has been around a very long time), it handles the basic onRequestStart functionality and is loaded before every *.cfm file.

You can add onRequestEnd functionality by creating a OnRequestEnd.cfm file.

Better reference: Coldfusion using onRequestEnd() with Application.cfm files

Scott Jibben
  • 2,229
  • 1
  • 14
  • 22
0

Please add requestStart.cfm file to you project, put your code in this file. It will run on every request (start).