Skip to main content
Inspiring
August 16, 2008
Question

Idiots guide to application.cfc

  • August 16, 2008
  • 16 replies
  • 2442 views
Hi all,
The code is my very simple application.cfm and onrequestend.cfm how do I combine them into an application.cfc? Thank you
This topic has been closed for replies.

16 replies

Inspiring
August 19, 2008
> Read Adam's references again. Pay particular attention to the onRequest function.

You beat me to it.

That said, I dunno why the links don't work just because of this.
Hyperlinks are a HTML construct which have no bearing and are not impacted
by however the underlying CF code is being called.

Hydrowizard:
What you you mean by "don't work"?

--
Adam
Inspiring
August 19, 2008
Read Adam's references again. Pay particular attention to the onRequest function.
BKBK
Braniac
August 17, 2008
Hydrowizard,
it is indeed a good idea to move to Application.cfc. In any case, you should be aware of the following corrections to your original code:

Application.cfm (with capital A)
OnRequestEnd.cfm (with capital O, R, E)
name = "mynew_app" (avoid space in application name)
avoid HTML tags in Application.cfm and OnRequestEnd.cfm

Having said that, your example might be translated into the following Application.cfc. There is a full example of Application.cfc in the livedocs. Have a look at it.



Inspiring
August 19, 2008
Thanks BKBK after Adam's advice to RTFM! I came up with this version which is almost like yours, mine wasn't working but I know now *why* I thought I did and it seems to be "working" now but I don't understand the concept please see below
Inspiring
August 19, 2008
Right two questions please
1. I just went through the code and I saw BKBK's commented out part saying "do you want to have time in london and login on each page" the answer is yes as I just want to replicate the OnRequestEnd.cfm that I have with the Application.cfm so this all is a bit strange. If I can't have html in the Application.cfc then do I just use a cfinclude instead and include the code on my former OnRequestEnd.cfm?
2. I had to include my index.cfm page on the OnRequestStart function to make it show but none of the links work. Do I have to cfinlcude all the .cfm pages now?!! Confused!! What do I do?!! Thanks
Inspiring
August 17, 2008
First, you transferred code that was supposed to run at the end of a request to one that is supposed to run at the end of a session.

Second, while not manadatory, it is a good idea to use the var keyword whenever setting a variable. This keeps it local and prevents the unintentional overwriting of variables in the calling template.

Third, the way I understand it, the this keyword applies to the entire cfc, not just the function. Also, it means that the variable value can be changed outside the function. Sometimes you want that, sometimes you don't. Changing the application name every time you start a session is probably something you don't want.
Inspiring
August 17, 2008
> The code is my very simple application.cfm and onrequestend.cfm how do I
> combine them into an application.cfc? Thank you

1) RTFM, which covers this:
http://livedocs.adobe.com/coldfusion/8/appFramework_03.html and specfically
this: http://livedocs.adobe.com/coldfusion/8/appFramework_15.html
2) Come back if - having done some background investigation - something is
still not clear.

This is a pretty simple requirement you have here, so just by following the
docs, you should get it sorted quickly.

It's always better in the first instance to try to help yourself, rather
than getting someone else to help you, because one learns more by DIY.

--
Adam
Inspiring
August 17, 2008
Thank you for those links Adam great stuff. Here's my attempt, it is a bit confusing about enabling session-what do you think of my attempt? Thanks
Inspiring
August 17, 2008
You can have a onRequestEnd function in your application.cfc.