0

Maybe the Title seems bit odd, but my question is straight, how can reinitialize the application with Application.cfm, i know how we do in Application.cfc like

<cfscript>
if(structKeyExists(url, 'reinit')) {
    onApplicationStart();
}
</cfscript>

But how in Application.cfm, not sure, please guide

Thanks

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Regual
  • 377
  • 1
  • 5
  • 20

2 Answers2

3

Firstly, running onApplicationStart() no more restarts the application than running an onClick() mouse-click event handler causes your mouse button to depress. onApplicationStart() is called as a result of the application starting, not the other way around.

Secondly, Application.cfm has nothing to do with the application lifecycle, it is merely a CFML file that is included at the beginning of every request. it is more closely associated with onRequestStart() than onApplicationStart(): the file is, unfortunately, misnamed. Its counterpart onRequestEnd.cfm demonstrates this.

I presume your requirement here is to re-initialise your application scope, yes? Do you have all your application-scope setting isolated in a specific CFML file, eg: applicationSettings.cfm, and then have logic like this in your Application.cfm:

// Application.cfm
if (!structKeyExists(application, "inited")){
    include "applicationSettings.cfm";
}

(then as a last thing in applicationSettings.cfm set application.inited to true).

If so you simply need to modify your condition to include your URL reinit variable, eg:

if (!structKeyExists(application, "inited") || structKeyExists(URL, "reinit")){
    include "applicationSettings.cfm";
}
Adam Cameron
  • 29,677
  • 4
  • 37
  • 78
  • Why require url.reinit to be a boolean - I generally just check it exists in the URL and leave it at that? I used to check true/false but I think only as a habit from Fusebox days... don't see a point to it now? (Of course, on a public server there's benefit to checking against a specific password for re-initing, to avoid potential appreload-based DoSing.) – Peter Boughton Aug 31 '13 at 12:40
  • Good point @PeterBoughton: force of habit. It's not like the thing is ever gonna be passed as "false" and for there to be a legitimate action to take if so ;-) (code updated) – Adam Cameron Aug 31 '13 at 12:46
  • When I push a site to production, I tend to set reinit to a value that cannot be easily guessed so that others cannot reinit the app. Why am I worried about that? I do not know. @AdamCameron - in my apps, I frequently have code that checks for value of 'reinit' in `onrequestStart()` that simplt calls `onApplicationStart()`. Not sure why you were implying this could not be done. – Scott Stroz Sep 01 '13 at 12:35
  • @ScottStroz where did I imply that, mate? What I said was running an event handler is not the same as the actual event occurring. Running `onApplicationStart()` does not - in and off itself - start the application, it merely reruns that code. The `onClick()` / mouse-button analogy is an easy way to understand it what I mean: running `onclick()` does NOT make the mouse button depress. That said, often when people say they want to restart their app, they *actually* mean they want to *reinitialise* their app, which is a different thing, and is acheived by rerunning `onApplicationStart()`. – Adam Cameron Sep 01 '13 at 13:20
  • @ScottStroz: good point re securing that URL better. We require both the `reinit` param to be passed, plus a password, plus - actually - has to be run from a specific - access-controlled - domain for it to work. Why? Belt & braces perhaps, but equally we have past employees which might want to be mischievous, and this saves them from that temptation. – Adam Cameron Sep 01 '13 at 13:22
  • @AdamCameron - I guess I misunderstood your meaning. My bad. – Scott Stroz Sep 01 '13 at 17:07
0

In OnRequestStart() put something like this:

param name='url.reloadApp' default='no';

if(url.reloadApp == 'yes')
{
    applicationStop();
}