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.
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.
I have one folder called misc which contains few sub folders and each sub folders has sub sub folders and files in it and I want to copy the sub folders, sub sub folders and its files in a called default folder.
I have tried this getting empty folder. And also I am wondering why Coldfusion doesn't have copy attribute in cfdirectory tag.
<cfset CurrentDirectory=GetTemplatePath()>
<cfset CurrentDirectory=ListDeleteAt(CurrentDirectory,ListLen(CurrentDirectory,"/\"),"/\")>
<cfset NewDirectory="#CurrentDirectory#\default">
<cfif NOT directoryExists(NewDirectory)>
<cfdirectory action="create" directory="#NewDirectory#">
</cfif>
<cfset strPath = ExpandPath("c:/wwwroot/test/misc") />
<cfdirectory action="list" directory="#strPath#" name="exDir">
<cfif exDir.type EQ 'File' >
<cffile action="copy" source="#strPath#" destination="#NewDirectory#" mode="777">
</cfif>
<cfif exDir.type EQ 'Dir'>
<cfdirectory action="create" directory="#NewDirectory#" mode="777">
</cfif>
<cfdump var = "#strPath#">
<cfdump var="#exDir#">
can anyone please let me know why I am getting empty folder ? any help would be appreciated!
directoryCopy() on cflib should do the job, or use cfzip
how to find the subfolder in the director in coldfusion
I did in cfdirectory . It shows the all files not the folder
this is my code
<cfoutput>
<cfloop index = "i" from = "1" to = "3">
<cfdirectory
action = "list"
directory = "#myarray[i]#"
name = "files"
filter="*.*"
type="all">
<cfset d="#files.recordcount#">
<cfoutput>
#d#
</cfoutput>
</cfloop>
</cfoutput>
In my application I have a header and footer include. In my Application.cfc I've set up a function that names my application and sets mapping.
<cfcomponent output="no">
<cfset this.name = "thesitename">
<cfset this.datasource = "thesitedatasource">
<cfset this.rootDir = getDirectoryFromPath(getCurrentTemplatePath()) />
<cfset this.mappings = structNew()>
<cfset this.mappings["/planning"] = "#this.rootDir#planning/" />
<cfset this.mappings["/images"] = "#this.rootDir#images/" />
<cfset this.mappings["/includes"] = "#this.rootDir#includes/" />
<cfset this.mappings["/js"] = "#this.rootDir#js/" />
<cfset this.mappings["/portfolio"] = "#this.rootDir#portfolio/" />
</cfcomponent>
If I have a page in a subdirectory like this: planning/index.cfm the <cfinclude> can't locate anything in the images folder when I use the following path: <li class="imagelink"><img src="/images/facebook.png"></li>
Pages in the root directory don't have a problem.
If I understand correctly, the problem has to do with the mapping doesn't take place prior to the include being called, or something like that... How do I get the mapped paths to work properly in my include?
ColdFusion mappings are completely separate from a web server 'alias' or 'virtual directory'. In order for your code to work, you will need to add a web server mapping, 'alias' in Apache or 'virtual directory' in IIS, named 'images' that points to the directory where you keep the images.
The 'images' ColdFusion mapping will only work in ColdFusion - for example, when creating an object, you could use createObject( "component", "images.image") (assuming of course that you had a CFC named Image in that diectory.
I am getting a problem with the following line:
<cfimage action="read" name="myImage" source="#ExpandPath("../../banner/#upload.clientfile#")#" />
I suspect it is because I am using a shared host (CF9) and do not have access to the folder. The error I get is "unable to create temporary file". My temp directory is home/kloxo/temp/wwwroot-tmp. Can I specify another temp folder or do I have to get my hosting company to sort this?
<cfapplication sessionmanagement="true">
<cfoutput>#GetTempDirectory()#</cfoutput>
<cfif IsDefined ("FORM")>
<cfif structKeyExists(form, "uploadfile")>
<cfset destination = expandPath("../../banner")>
<cfif not directoryExists(destination)>
<cfdirectory action="create" directory="#destination#">
</cfif>
<cffile action="upload" filefield="uploadfile" destination="#destination#" nameConflict="makeUnique" result="upload">
<cfdump var="#upload.clientfile#">
<cfimage action="read" name="myImage" source="#ExpandPath("../../banner/#upload.clientfile#")#" />
</cfif>
It appears to be a configuration issue. Contact your host. Here is a page with more information:
http://forums.adobe.com/message/3060530