Skip to main content
BreakawayPaul
Inspiring
December 18, 2012
Answered

Newb question about Application.cfc vs .cfm

  • December 18, 2012
  • 3 replies
  • 19834 views

Sorry for this total newb question that's probably been covered a bazillion times, but I'm having some trouble getting things to work.  I should know all this stuff, as I've taken the CF9 advanced training, but when you have 60,000 pages worth of content back at the office waiting to be converted to a new design, there isn't much time to practice what you learned in class.

A lot of my office's website is leftover from when we were running CF 6.1, so everything uses Application.cfm files.  Now that we're running CF8 (and may soon move to something even newer), I'd like to get everything modernized, including getting my Application.cfm stuff into an Application.cfc file.  One of the reasons I want to do this is because I have a few apps that I want to use OnRequestStart() methods for.

My problem stems from the fact that our Application.cfm file does a lot of things like setting global variables, doing queries, and other things that I can't seem to get to work inside an Application.cfc file.  Particularly odd is the fact that I recently set up a CF10 site for my wife's business's websites and was able to get Application.cfc working without much trouble, leading me to suspect a setup problem with my office.

I tried following the guide on Hostek's forum, but to no avail.  I can't seem to include the contents of our old Application.cfm file in the new cfc.

Any tips?

    This topic has been closed for replies.
    Correct answer BKBK

    Everything's lowercase.  It's a Windows machine, so not case sensitive.

    This is what's in the included file:

    <cfquery name="userdata" datasource="hepoffice">

    SELECT usernm, user_email, admin

    FROM users

    WHERE usernm = '#listlast(GetAuthUser(),"\")#'

    </cfquery>

    <cfif userdata.recordcount eq 0>

    <cflocation url="noaccess.html">

    </cfif>

    <cfset rights = userdata.admin>

    <cffile action="read" file="D:\inetpub\fhwaroot_test\includes\hep\acronyms.xml" variable="myxml" />

    <cfset variables.acrXML = XmlParse(myxml) />

    <cfset variables.acrList = acrXML.acronyms.XmlChildren />

    <cfset variables.acrListSize = ArrayLen(acrList) />

    <cfset variables.acrQuery = QueryNew("id, name, old, new") />

    <cfset variables.acrTemp = QueryAddRow(acrQuery, #acrListSize#) />

    <cfloop index="i" from="1" to="#acrListSize#">

    <cfset variables.acrTemp = QuerySetCell(acrQuery, "id", #i#, #i#) />

    <cfset variables.acrTemp = QuerySetCell(acrQuery, "name", #acrXML.acronyms.acronym.name.XmlText#, #i#) />

    <cfset variables.acrTemp = QuerySetCell(acrQuery, "old", #acrXML.acronyms.acronym.old.XmlText#, #i#) />

    <cfset variables.acrTemp = QuerySetCell(acrQuery, "new", #acrXML.acronyms.acronym.new.XmlText#, #i#) />

    </cfloop>


    BreakawayPaul wrote:

    <cfset rights = userdata.admin>

    <cffile action="read" file="D:\inetpub\fhwaroot_test\includes\hep\acronyms.xml" variable="myxml" />

    <cfset variables.acrXML = XmlParse(myxml) />

    <cfset variables.acrList = acrXML.acronyms.XmlChildren />

    <cfset variables.acrListSize = ArrayLen(acrList) />

    <cfset variables.acrQuery = QueryNew("id, name, old, new") />

    <cfset variables.acrTemp = QueryAddRow(acrQuery, #acrListSize#) />

    <cfloop index="i" from="1" to="#acrListSize#">

    <cfset variables.acrTemp = QuerySetCell(acrQuery, "id", #i#, #i#) />

    <cfset variables.acrTemp = QuerySetCell(acrQuery, "name", #acrXML.acronyms.acronym.name.XmlText#, #i#) />

    <cfset variables.acrTemp = QuerySetCell(acrQuery, "old", #acrXML.acronyms.acronym.old.XmlText#, #i#) />

    <cfset variables.acrTemp = QuerySetCell(acrQuery, "new", #acrXML.acronyms.acronym.new.XmlText#, #i#) />

    </cfloop>

    If you wish these variables (included in Application.cfc) to be available to every requested page, then you should store them in the request scope instead.

    3 replies

    BKBK
    Community Expert
    Community Expert
    December 18, 2012

    As Adam has suggested, if you show us your Application.cfm, I am sure you will get many suggestions pronto.

    Inspiring
    December 18, 2012

    I suggest preserving the Application.cfm files unless you have a specific reason to convert them.  What's that old saying?  If it ain't broke, don't fix it.

    Inspiring
    December 19, 2012

    I suggest preserving the Application.cfm files unless you have a specific reason to convert them.  What's that old saying?  If it ain't broke, don't fix it.

    Disagree. If there's major upheaval (like an upgrade from 6.1 to 8) that's going to necessitate a full retest anyhow, it's precisely the time to modernise code like this. Especially if one wants to leverage the new features it offers. In this case it's also a fairly straight-forward migration, too.

    Application.cfm is dead, and everyone who's in the position to should have moved off it by now. We're not talking about something that came out in the last version of CF... it's been around for seven years now.

    --

    Adam

    Inspiring
    December 18, 2012

    Yep, first tip: show us the code that isn't working, and explain in what way it's not working, ie: what you expect it to do, and what it's doing instead.

    Other than that, your question is too nebulous to be able to answer properly beyond "yeah, it should all work".

    --

    Adam

    BreakawayPaul
    Inspiring
    December 18, 2012

    Well as far as code goes I basically just copied an Application.cfc example template from a website and edited it.

    What I have now is basically this:

    <cfcomponent>

    <cfscript>

    this.name = "hepcms";

    this.sessionManagement = "Yes";

    this.sessionTimeout = CreateTimeSpan(0,1,0,0);

    this.setClientCookies = "Yes";

    </cfscript>

    <cffunction name="onRequestStart">

    <cfargument name="requestname" required=true />

    <cfinclude template="application.cfm">

    </cffunction>

    </cfcomponent>

    Thing is, I'm not sure I even need an application name, since this is just the CMS for the website.

    @Dan

    The reason I'd like to do this change is because I want to use the OnRequestStart feature in Application.cfc.  Our CMS used to have a cflogin, and I would record who logged in and at what time/date.  Now we've been forced to switch to a central type of authentication that works similar to password protected directories. 

    Once we log in to access the CMS folder, credentials are contained in GetAuthUser().  I want to still be able to see who logged in and when, but I can't use the old method.

    Also, with my wife's website, I was able to use Application.cfc to add common headers and footers to each page without having the includes directly on the pages.  This is something else I'd like to implement.

    Inspiring
    December 18, 2012

    You do need an application name.

    Get rid of the <cfinclude template="application.cfm"> tag.