My Application.cfc file has (see below): In my &lt...
# cfml-beginners
j
My Application.cfc file has (see below): In my <cfquery> I can't use #datasource# or I get qet blank page, but if I use cfhawaii everything works. am I doing something wrong?
Copy code
component {

    this.name = "myApplication";
    this.applicationTimeout = CreateTimeSpan(0, 2, 0, 0); //2 hours
    this.datasource = "cfhawaii";
    this.sessionManagement = true;
    this.sessionTimeout = CreateTimeSpan(0, 0, 30, 0); //30 minutes
    this.customTagPaths = [ expandPath('/myAppCustomTags') ];

    function onApplicationStart() {
        return true;
    }

    function onSessionStart() {}

    // the target page is passed in for reference,
    // but you are not required to include it
    function onRequestStart( string targetPage ) {}

    function onRequest( string targetPage ) {
        include arguments.targetPage;
    }

    function onRequestEnd() {}

    function onSessionEnd( struct SessionScope, struct ApplicationScope ) {}

    function onApplicationEnd( struct ApplicationScope ) {}

    function onError( any Exception, string EventName ) {}

}
d
@johnbarrett You can exclude the data source attribute from your cfquery and it will use your default, which would be the one you are defining in your Application.cfc.
👍 2
1
j
@danmurphy thanks so much! I took out the data source attribute and it works. I didn't know this, thanks so much :)
👍 2
a
@danmurphy's answer kinda address the problem, but didn't explain why that was the fix. It's important to understand things, not simply apply fixes to things. There's a few things to note here:
this.datasource
is an application setting, not a variable. You can use it as a variable within Application.cfc, but it's not then exposed as a variable
datasource
elsewhere in your app. If you need an application-wide variable (which is where DSNs are often set), then you'd also need to set
application.datasource
in your
onApplicationStart
handler. You are including your requested file in your
onRequest
handler, so your entire request will be running in the context of that Application.cfc instance, so you should be able to use
this.datasource
, rather than just
datasource
. That said... the whole point of setting
this.datasource
is so you don't need to specify the datasource every time you need to use it. ---
In my <cfquery> I can't use #datasource# or I get qet blank page
This is odd behaviour. You should be getting an error along the lines of "`Element datasource is undefined in VARIABLES`". That you're getting a blank page indicates something ain't configured right / well..? --- From a tidiness POV, none of those other event handlers in your Application.cfc are doing anything. There's no point in having them in there.
👍 4
m
I love when Adam brings in the big guns, thank you sir. As for the blank page thing, John we should try and figure that out for ya, because that's a pretty major issue. Is the error showing up in your application error log at least? This came up before when John was trying to dump out data from a different query. Nothing but a blank page. Something is blocking basically all errors from showing. Is your onError() code block in application.cfc pointed to a blank .html template or something like that John?
👍 1
m
empty onError() is why you get a blank page, along with the error being on the first line of your template, or at least before any expected output. Had you put non-breaking stuff before the error, it would have displayed. comment out the onError() function, and you will see something useful. It IS in most casese, better to leverage the onError() though. onError is going to need to create the content to display, for testing purposes, just put
writeDump(exception);
👍 2
a
Oh I didn't notice that was one of the extraneous event handler methods, @Matt Jones. I refer back to my advice to get rid of all the ones yer not using, @johnbarrett. Not only are they pointless clutter (my concern), they also can cause "unexpected" behaviour, as per here.
Only ever have code you're actively using.
👍 3
j
@Adam Cameron thanks so much for teaching me so much about my Application.cfc file! I got rid of the handlers that are not being used. This is my first script-style Application.cfc. I like the point that I don't need to include the data source everytime I use it.
❤️ 1
@Mark Takata (Adobe) Adam has taught me so much! I have no idea why I get a blank page, maybe like adam says it's the handlers not doing anything. They are gone now.
@Matt Jones thanks so much for your help. I didn't know until now that empty handlers in the Application.cfc would cause weird behavior like getting a blank page when I should be seeing an error. I am still learning about the Application.cfc file.