ColdFusion Application.cfc - order of execution

前端 未结 5 554
旧巷少年郎
旧巷少年郎 2021-01-05 00:34

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) - re

5条回答
  •  星月不相逢
    2021-01-05 01:07

    Anything in the this scope inside an Application.cfc file becomes an application varialbe and is only created ONCE per application life cycle. After the application starts, there is no other user for this within Application.cfc.

    The first time a CF application is run, the contents of onApplicationStart() are run before onRequest/Start/End (with the exception of the "new in CF10" onServerStart()).

    Any application variables set anywhere in the application exist until the application is stopped.

    Your code from #3 should just be

    if ( !structKeyExists( application, "myvar" ) { application.myvar = foo; }

    then reference application.myvar wherever you need it.

    From your description, nothing needs to be added to the this scope, it just needs to be put in the application scope.

提交回复
热议问题