Reputation: 69
I'm moving away from ColdFusion 8 to ColdFusion 10.
Currently, on my Unix's root directory, I only have 1 Application.cfm and under this root directory I have about 10 sub directories (previous programmers did it this way and I'm experiencing a lot of weird things).
Now that I get the chance to redo this web application, I want to do it properly but the biggest problem with me is to properly understand how to work with Application.cfc in CF10.
Each of the sub directory represents a web application. For example, there is a web application for tracking graduate students, a web app. for tracking alumni, a web app. for formatting addresses, etc.
Users for these applications are from 10 different institutions. They all login to the application the same way (from the same interface) but then we separate them using session.usergoup
& session.username
to know who is who and who can see what type of things.
All Institutions share the same database, so currently only the datasource is set to application scope.
Unfortunately after reading many Application.cfc postings at this forum I got even more confused, so I hope you guys don't mind assisting me so that I can feel more comfortable working with Application.cfc in CF10.
My understanding is:
On my root dir I will create one main Application.cfc. My Main Application.cfc will only handle login/user authentication.
So under this root dir, I will have 1 Application.cfc, loginform.cfm and loginaction.cfm
In loginaction.cfm is where I set session.usergroup
and session.username
upon successful user authentication.
So in my main Application.cfc, I should set the following:
<cfset THIS.Name = "InstitutionMainApp" />
<cfset THIS.ApplicationTimeout = CreateTimeSpan(0,0,30,0) />
<cfset THIS.SessionManagement = true />
<cfset THIS.SetClientCookies = false />
under OnApplicationStart I'll do:
<cfset application.dsn = "MyDB">
and under OnSessionStart I'll do:
<cfset session.usergroup= "">
<cfset session.username= "">
Then on each of my sub-folder's Application.cfc I need to name it differently For graduate tracking system I should have:
<cfset THIS.Name = "GraduateTrackingSystem" />
<cfset THIS.ApplicationTimeout = CreateTimeSpan(0,0,30,0) />
<cfset THIS.SessionManagement = true />
<cfset THIS.SetClientCookies = false />
under OnRequestStart, when I need to encrypt url variable (form example), I can set:
<cfset request.mySecretKey = application.mySecretKey />
<cfset request.algorithm = "AES" />
<cfset request.encoding = "hex" />
For alumni tracking system I should have:
<cfset THIS.Name = "AlumniTrackingSystem" />
<cfset THIS.ApplicationTimeout = CreateTimeSpan(0,0,30,0) />
<cfset THIS.SessionManagement = true />
<cfset THIS.SetClientCookies = false />
under OnRequestStart, when I need to encrypt url variable (form example), I can set:
<cfset request.mySecretKey = application.mySecretKey />
<cfset request.algorithm = "AES" />
<cfset request.encoding = "hex" />
For Address Formating app., I should set:
<cfset THIS.Name = "AddressFormattingSystem" />
<cfset THIS.ApplicationTimeout = CreateTimeSpan(0,0,30,0) />
<cfset THIS.SessionManagement = true />
<cfset THIS.SetClientCookies = false />
under OnRequestStart, when I need to encrypt url variable (form example), I can set:
<cfset request.mySecretKey = application.mySecretKey />
<cfset request.algorithm = "AES" />
<cfset request.encoding = "hex" />
Then since the application.dsn
, session.usergroup
and session.username
are all set in
the Main Application.cfc under the root dir., I can freely use these scoped variables
on each application sub-folder safely because each of sub-folder application.cfc is
named differently this way I should not be concern with cross reference among usergroup
and username?
Please let me know if my understanding on how to use Application.cfc is very much a mess.
Upvotes: 3
Views: 4451
Reputation: 32885
That's a long question.
I think this is what you need: http://corfield.org/blog/index.cfm/do/blog.entry/entry/Extending_Your_Root_Applicationcfc
Once you have extended your application.cfc via some proxy to workaround the limitation of extending itself, you should be able to do almost anything your existing application.cfm was setup to do.
update: as iKnowKungFoo pointed out in the comment, once you have a different application name i.e. this.name
you cannot share the vars in the Application
scope since you're essentially forking a new application, you may try Server
scope for those. Logic can be shared via functions you have inherited, but pay attention to whether the vars are accessible in your application.
Upvotes: 2