Skip to main content
Inspiring
October 15, 2012
Question

Using application.cfc instead of application.cfm

  • October 15, 2012
  • 1 reply
  • 3113 views

I just discover the role of application.cfc

seems very interesting.

All my applications are using an application.cfm template.

I have seen in the doc the migration from application.cfm to application.cfc,

but I do not understand.

Is the application.cfc running instead of application.cfm ?

With the application.cfc , I have a blank page, no error messages, I do not know what to do.

why it does not go to the index.cfm as it did with application.cfm

If I take all the content of my current application.cfm

where can I put it in the application.cfc ?

I tried in : 

<cffunction name="OnRequestStart"

but no thing happended.

thanks for help with this major change. (I am running CF8).

Pierre.

This topic has been closed for replies.

1 reply

Inspiring
October 15, 2012

If I had a perfectly good application running with Application.cfm I would not change it.  Having said that, if I did have a reason to change it, I would put stuff in the functions where I want them to run.

If you google, "adam cameron coldfusion" you'll see a link to a blog he has written.  Somewhere in that blog is some guidance on how to use the functions in Application,.cfc.

plartsAuthor
Inspiring
October 16, 2012

Thanks for your reply,

I would like to use application.cfc  to use the "OnSessionEnd()" function.

Also in me old application, moving from application.cfm to application.cfc,

I get a blank page.  Debugging :

In the CFC  OnApplicationStart , I put :

<cfset pres_datasource="A01_onvide">  (the datasource)

And when doing a query on this datasource, the datasource variable is "blank",

no error message.

Any idea ?

thanks.

I will look at : adam cameron coldfusion blog

thanks for your help.

Pierre.

Miguel-F
Inspiring
October 16, 2012

Even though you have placed the setting of your variable in OnApplicationStart you still need to specify the application scope.

Change the statement in your Application.cfc to:

<cfset application.pres_datasource="A01_onvide">

And then in your code, reference the variable like this:

<cfquery name="qname" datasource="#application.pres_datasource#" ... >

By the way, that should be the same way it was done in application.cfm

If you are not wanting to set the variable in the application scope for some reason then you could move your statement as it is (without specifying the application scope) to the OnRequestStart method instead.  That method runs on every request so the variable would be set on every request.  Then you would not need to change your cfquery references.  Just another way...  For what it's worth, I always set my datasources in the application scope.