简体   繁体   中英

How to call OnRequestStart from Application.cfm

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?

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM