ColdFusion Application.cfc - 执行顺序 [英] ColdFusion Application.cfc - order of execution

查看:195
本文介绍了ColdFusion Application.cfc - 执行顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



CF应用程序框架评估事物的方式是这样的(我的理解)。我需要一个真实的检查,希望有一个解释(如果我的现实是错误的)
- 请求传递给cfserver




  • cf找到application.cfm或cfc(基于遍历规则) / p>

  • strong>范围设置(可以在此处设置一系列应用程序特定的变量,但




applicationTimeout - 然后发生一系列事件,并根据需要激活方法。



- onApplicationStart()



---- onSessionStart()



------ onRequestStart()





所以我的问题



1)THIS设置发生在每个页面请求 - / p>

2)如果我设置一个应用程序变量,在onApplicationStart() - 它可以在任何进程后发生 - AND应该持久在内存中的applicationTimeout ) - 正确?



3)所以如果我这样做...



if application.myvar){
this.something = application.myvar;
}



它应该在启动应用程序范围的初始请求之后的任何页面请求上工作。



但是它似乎没有这样做。



我的原因是这是 - 有趣的应用程序杠杆设置,需要在THIS范围中设置...其中一些可能是'密集型'(至少形成在每个请求执行的角度 - 所以我想只做他们的ONCE,设置一个结构



我做错了假设?



thx

解决方案

ColdFusion Application.cfc文档有这样的知识:


ColdFusion按照以下顺序在
中运行CFC方法:


  1. onApplicationStart(如果此应用程序未运行) li>
  2. onSessionStart(如果此会话之前未运行)

  3. onRequestStart

  4. onRequest / onCFCRequest

  5. onRequestEnd

onApplicationEnd,onSessionEnd和onError CFC由特定事件触发。


整个请求订单至少还有两个步骤。


0:执行不在 cffunction

0.5中的所有代码 cfcomponent :运行相当于 cfapplication 标记来创建应用程序


您的问题的答案是:


  1. 如果您在步骤0中设置这些变量,那么是。

  2. 正确。

  3. 这取决于您设置变量的位置。如果您尝试更改的值列在应用程序变量Application.cfc的文档页面,那么它们必须在步骤0.在其他地方设置它们会更新 this 作用域,但不会在步骤0.5中生效。 / li>


I need a reality check - and hopefully an explanation (if my reality is wrong).

The way the CF application framework evaluates things is this (my understanding) - request is passed to cfserver

  • cf finds an application.cfm or cfc (based on traversing rules)

  • application.cfc executes (if found)

  • the THIS scope is set (a series of application specific vars can be set here but

some are required - such as "applicationTimeout" - then a series of events takes place -and methods fired if needed.

-- onApplicationStart()

----onSessionStart()

------onRequestStart()

etc.

so my questions

1) The THIS settings happens on EVERY page request - before anything else?

2) If I set an application variable, in onApplicationStart() - it is available in any process that happens after that - AND should persist in memory for the length of applicationTimeout() - correct?

3) so if I do something like this...

if ( isdefined("application.myvar" ) { this.something = application.myvar; }

it SHOULD work on any page request after the initial request that started the application scope.

however it doesn't appear to do so.

my reason for asking is this - there are some interesting application lever settings that need to be set in the THIS scope... a few of them could be 'intensive' (at least form the perspective of executing on EVERY request - so I want to do them only ONCE, set a structure in persistent mem, and then have those available as THIS.

am I making some wrong assumptions?

thx

解决方案

The ColdFusion Application.cfc documentation has this tidbit of knowledge:

When a request executes, ColdFusion runs the CFC methods in the following order:

  1. onApplicationStart (if not run before for this application)
  2. onSessionStart (if not run before for this session)
  3. onRequestStart
  4. onRequest/onCFCRequest
  5. onRequestEnd

The onApplicationEnd, onSessionEnd, and onError CFCs are triggered by specific events.

The overall request order has (at least) two more steps.

0: execute all code in cfcomponent that isn't in a cffunction
0.5: run the equivalent of the cfapplication tag for creating the Application

As such the answers to your questions are:

  1. If you're setting those variables in step 0, then yes.
  2. Correct.
  3. That depends on where you're setting the variable. If the values that you are trying to change are listed on the Application variables documentation page for Application.cfc then they must be in step 0. Setting them elsewhere will update the this scope, but will not take effect in step 0.5.

这篇关于ColdFusion Application.cfc - 执行顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆