Skip navigation
Currently Being Moderated

Newb question about Application.cfc vs .cfm

Dec 18, 2012 6:26 AM

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?

 
Replies
  • Currently Being Moderated
    Dec 18, 2012 6:31 AM   in reply to BreakawayPaul

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 18, 2012 7:21 AM   in reply to BreakawayPaul

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 18, 2012 7:35 AM   in reply to BreakawayPaul

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

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 18, 2012 8:34 AM   in reply to BreakawayPaul

    You do need an application name.

     

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

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 18, 2012 8:50 AM   in reply to Dan Bracuk

    Dan Bracuk wrote:

     

    You do need an application name.

    There is an application name. Unless you wish to emphasize the point.

     

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

    No need to get rid of it. As long as the file name begins with small-letter 'a' and the file contains appropriate code.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 18, 2012 10:14 AM   in reply to BreakawayPaul

    What does the included code look like?

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 18, 2012 10:44 AM   in reply to BreakawayPaul

    BreakawayPaul wrote:

     

    However, the include doesn't work.  Any variables set in that include are undefined. 

    Did you save the file as Application.cfc, with capital A.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 18, 2012 12:13 PM   in reply to BreakawayPaul

    BreakawayPaul wrote:

     

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

    Use the file name Application.cfc, even on Windows.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 18, 2012 12:13 PM   in reply to BreakawayPaul

    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[i].name.XmlText#, #i#) />

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

    <cfset variables.acrTemp = QuerySetCell(acrQuery, "new", #acrXML.acronyms.acronym[i].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.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 19, 2012 7:13 AM   in reply to BKBK

    BKBK wrote:

     

    BreakawayPaul wrote:

    <cfset rights = userdata.admin>

     

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

    [...]

    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.

     

    Or, use the onRequest() interceptor to include the requested template, then it will get executed in the same memory space as Application.cfc, so its variables scope will be shared throughout the request. IE: the request will use Application.cfc's variables scope.

     

    --

    Adam

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 19, 2012 7:16 AM   in reply to Dan Bracuk

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 19, 2012 9:32 AM   in reply to BreakawayPaul

    BreakawayPaul wrote:

     

    I should probably figure out how to do that, because I just noticed that any queries done in the included application.cfm (which I'll likely rename) are not accessible on any of the pages in the application.

    You needed <cfquery name="request.userdata" datasource="hepoffice">

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 19, 2012 10:54 AM   in reply to BreakawayPaul

     

    BreakawayPaul wrote:

     

    In the old CMS, I used to keep the name of the last logged-in user in the database, and that would display on the front page when the next person logged in.  That way if something weird got changed, you knew who to ask about it.

     

    With no cflogin, I'm hoping I can use something like OnSessionStart() (or End()) to do this same thing, but my trial and error hasn't been going well.

     

    They way you describe it, userLastLoggedIn is user-dependent, hence a session variable. For example, when I log in, my value of session.userLastLoggedIn is the user who last logged in before me. If you're the next to log in after me, your value of session.userLastLoggedIn will be me.

     

    The variable has to be available thoughout my session. So the best place to set it is in onSessionStart.

    And how does the Session timeout affect things?  If no one requests a page before the session timeout occurs, does the session end?  Not that it matters, because the way we're authenticating, it would just renew the credentials.

     

    You have set the sessiontimeout value at 1 hour. It means that a user's session will end if the user doesn't make any requests to the server in a period of 1 hour. Users don't share sessions. The server gives each user his own. Therefore, if after logging in you go away for an hour, the server will time your session out. That there are a thousand other users active on the server has no effect on your session.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 20, 2012 5:11 AM   in reply to BreakawayPaul

    Sounds more like you doing something wrong than it does a wierd access thing.  Breaking a timestamp into two fields makes sense in some situations, but not yours.  But if you are going to do it, you may as well do it properly and send a date to your date field, not a string.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 20, 2012 5:32 AM   in reply to BreakawayPaul

    BreakawayPaul wrote:

     

    Today it told me that the last user (me) logged in back in December of 1899.  Either the webserver has a time setting problem or something else is wrong.   Besides, I only look like I was around in 1899.

    When you store just the time in a datetime variable, ColdFusion will use December of 1899 as the default month and year. This code snippet shows you what I mean:

     

    <cfset t = parseDateTime("9:30 AM")>

    <cfoutput>#t#</cfoutput>

     

    Since the credentials are always "there" from IE, nothing seems to ever time out, even if I make the session time 10 seconds.  Firefox users get a login box, but their session never seems to timeout either.  I guess I'll leave the session timeout at an hour, since it won't hurt anything.

    Should you ever wish to link login to session timeout, then consider the setting this.loginStorage="session".

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 20, 2012 5:38 AM   in reply to BreakawayPaul

    BreakawayPaul wrote:

     

    To fix this I had to use two separate fields, and update them differently.  After trying it probably two dozen different ways, this is the only thing I could get to work:

              lastlogintime = <cfqueryparam value="#Now()#" cfsqltype="cf_sql_time">

            , lastlogindate = <cfqueryparam value="#dateformat(Now(),"mm-dd-yyyy")#" cfsqltype="cf_sql_date">

     

    In Access both field types are Date/Time.

     

    Hopefully once we get MSSQL working properly, things like that will stop being an issue.

    As temporary solutions go, this one is quite good.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 20, 2012 9:05 AM   in reply to BreakawayPaul

    If you insert now() into a table, select the field with a cf query, and cfdump that query, do you get the proper date and time?

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 20, 2012 2:56 PM   in reply to BreakawayPaul

    So when you saw something else earlier, it wasn't necessarily bad data.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points