简体   繁体   English

如何从Application.cfm调用OnRequestStart

[英]How to call OnRequestStart from Application.cfm

I am a new to ColdFusion. 我是ColdFusion的新手。 I have Application.cfm and would like to add an onRequestStart function, but it is not working. 我有Application.cfm,想添加一个onRequestStart函数,但是它不起作用。 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. 所谓不工作,是指当页面调用某些应用程序变量(在o​​nRequestStart内设置)时,会生成错误,因为这些变量不存在。

I can't use Application.cfc. 我不能使用Application.cfc。 Is there a solution or another way to use onRequestStart with Applciation.cfm? 是否存在将onRequestStart与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) 因此,我不确定自己要如何对Application.cfm进行尝试,但是就像Ageax所说的那样,Application.cfm会在每个请求上运行(无论您打算在onRequestStart()函数中执行什么工作流程,都可以在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中使用onRequestStart函数,则可以制作自己的函数并像下面这样显式调用它


Application.cfm 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 如果您不被迫使用Application.cfm,则此问题和文章可能对您来说很有趣

ColdFusion: Are there any use cases where an Application.cfm is preferable to an Application.cfc ColdFusion:在任何用例中,Application.cfm比Application.cfc更可取

Migrating from Application.cfm to Application.cfc 从Application.cfm迁移到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. 如果您需要使用Application.cfm(不知道为什么会有这个要求,因为Application.cfc已经存在很长时间了),它将处理基本的onRequestStart功能,并在每个* .cfm文件之前加载。

You can add onRequestEnd functionality by creating a OnRequestEnd.cfm file. 您可以通过创建OnRequestEnd.cfm文件来添加onRequestEnd功能。

Better reference: Coldfusion using onRequestEnd() with Application.cfm files 更好的参考: 使用onRequestEnd()和Application.cfm文件进行Coldfusion

Please add requestStart.cfm file to you project, put your code in this file. 请向您的项目添加requestStart.cfm文件,并将您的代码放入该文件中。 It will run on every request (start). 它将在每个请求(启动)上运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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