If I have a folder A and a subfoder AB and an appl...
# cfml-general
b
If I have a folder A and a subfoder AB and an application.cfc in each one with an onApplicationStart in each one and I request a page from the A folder first, then a page from the AB subfolder, will both onApplicationStart methods be executed, bad practices aside?
a
Depends on the application name
And by the sounds of it, one Application.cfc does not extend the other one?
Application state is bound to the app name. Where the files are doesn't really matter, unless there's inheritance etc going on.
b
Same application name, no extension. But where the files are determines which application.cfc is run, right?
a
Yep. Closest "ancestor"
And it only processes one. So like once it finds an Application.cfc, it does not keep looking upwards for more
b
Right. But if it's already processed an onApplicationStart in the upper folder, does it process the one from the lower folder when that lower folder page is called? The application is already started, but...
a
Application.cfc is loaded every request
The look-up is independent of the state of the application. Application.cfc is just the file that has the application lifecycle even handlers in it. CF needs to know where they are every request.
And it's entirely possible to have an application state for more than one application at once.
So one could hit a URL in A, and A/Application.cfc will be loaded, and its application.name will be used for checking the state of that application. Then one hits a URL in A/B, and A/B/Application.cfc will be loaded, and its application.name will be used for checking the state of that application. Which is entirely different from the state of the application named in A/Application.cfc
b
But what if both application.cfcs have the same application name? Does it then skip executing the second onApplicationStart?
a
yes, because the application with that name is already in a started state
Remember that the methods in the Application.cfc are event handlers, they are nothing to do with actually dictating the application state
Analogy: The application state is the mouse button. The functions in Application.cfc are onclick functions.
The onclick functions don't make the mouse button depress.
b
Okay, that's what I suspected but couldn't find clear support in the documentation. This may explain a few things. lol Thanks @Adam Cameron! Gotta love legacy code.
1
a
Ping if you need anything else reasoned-through, etc
b
I'm trying to transition some legacy code to new CF2021 servers as quickly as possible. Is there a way to have the application.cfc in the subfolder include the application.cfc in the parent folder without causing problems? Most of the code that's in the subfolder cfc's really shouldn't be there, but I don't want to take the time now to deal with all of those.