Moving to CF10, Need help with Application.cfc
I've been googling about how to work with Application.cfc since last week but I still have some questions and I can't find the answers.
My application is under the root (in unix) and there are many subfolders underneath it. Each sub-folder is hosting a different web application.
From what I read, I can create 1 root Application.cfc and then on subsequent sub-folder, when I need to have another Application.cfc on that level, I can create ProxyApplication (see below) and then create a sub-folder level Applicatin.cfc
So, when I set an application.DSN on my root Application.cfc, using proxyApplication I don't have to reset this dsn again in my sub folder level Application.cfc
Since my loginform.cfm and loginaction.cfm is right under root directory too, I also set OnsessionStart in the root Application.cfc to handle user login. Then this means, I don't have to reset session variable again anywhere because session.username, etc has been set on the highest level.
Is this correct?
In addition, Am I correct when I do the following:
1. Since I have root level and sub-folder level Application.cfc, I should set this.name with a different name, am I right?
On the root Application.cfc I set this.name = "StudentServices" because this represent the global application
On the sub-folder level's Application.cfc, I set this.name to "StudentServices_stdLoad" becaus this sub-folder only handle student load application.
2. On the root Application.cfc, I set the DSN to the application scope. So on the sub-folder level Application.cfc I can check if a particular db is working or not
because as awhole, in the global sense, this web application uses more than one Databases. Each sub-folder may use a database that is dfferent than the other sub folder.
Am I doing the right thing? Please advice
Below is example of what I have, Thank you!
I created a root Application.cfc under the root directory:
<CFCOMPONENT displayname="Application" output="true" hint="My Root Application component">
<!--- Set up the application --->
<cfset THIS.Name = "StudentServices" /> <cfset THIS.ApplicationTimeout = CreateTimeSpan(0,0,30,0) /> <cfset THIS.SessionManagement = true /> <cfset THIS.SetClientCookies = false /><cffunction name="OnApplicationStart" access="public" returntype="boolean" output="false">
<cfset application.MainDSN = "DSN1">
<cfset application.ReportDSN = "DSN2">
<cfreturn true/>
</cffunction>
<cffunction name="onApplicationEnd" output="false"><cfargument name="applicationScope" required="true"> </cffunction>
<cffunction name="onSessionEnd"></CFCOMPONENT>
Then, in this root directory I also created a ProxyApplication:
<!--- it's empty and it Serves merely to create an alias for your root /Application.cfc ---><cfcomponent name="ApplicationProxy" extends="AdvancementServices.Application">
</cfcomponent>
Then in the Sub-Directory, I can create a sub-folder level Application.cfc extending the root Application.cfc:
<CFCOMPONENT displayname="Application" extends="ApplicationProxy"><!--- Set up the sub-folder application --->
<cfset THIS.Name = "StudentServices_stdLoad"/>
<cfset THIS.ApplicationTimeout = CreateTimeSpan(0,0,30,0) />
<cfset THIS.SessionManagement = true/>
<cfset THIS.SetClientCookies = false/>
<cffunction name="OnApplicationStart" access="public" returntype="boolean" output="false">
<!--- ****** Testing whether the ADVUPGRD is accessible by selecting some data.****** --->
<cftry>
<cfquery name="TestMain_DSN" datasource="#application.MainDSN#" maxrows="2">
SELECT Count(*)
FROM MyTable
</
cfquery>
<!--- If we get a database error, report an error to the user, log the error information, and do not start the application. --->
<cfcatch type="database">
<cflog file="#this.name#" type="error" text="Main DSN is not available. message: #cfcatch.message# Detail: #cfcatch.detail# Native Error: #cfcatch.NativeErrorCode#" >
<cfthrow message="This application encountered an error when connecting to the Main Database. Please contact support." />
<cfreturn false>
</cfcatch>
</cftry>
<cflog file="#this.name#" type="Information" text="Application #this.name# Started">
<cfreturn true/>
</cffunction>
</CFCOMPONENT>
<cfargument name = "SessionScope" required=true/> <cfargument name = "AppScope" required=true/>
</cffunction>
<cffunction name="OnSessionStart" access="public" returntype="void" output="false">
<CFSET session.UserGroup = ""/>
<CFSET session.UserName = ""/>
<CFSET session.currentPage = ""/>
<CFSET session.loggedin = "No"/>
<CFSET session.userrights = ""/>
<cfreturn/>
</cffunction>
