Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How application.cfc is supposed to work (AJAX & onRequest)

Enthusiast ,
Aug 23, 2010 Aug 23, 2010

I'm an intermediate CF developer using CF8 on a Windows 2k3 box.  We are using AJAX, and as such are using the following chunk o' code in the onRequestStart to ensure AJAX calls don't have issue:


<cfif listLast( cgi.cf_template_path, '.' ) is 'cfc'>

  <cfset structDelete( this, 'onRequest' ) />

</cfif>

Everything is working fine, however, when I perform an AJAX call to a file that resides at: /framework/com/page.cfc  I get an error message that seems to be the application.cfc firing off from the com folder (located at /framework/com)  It states it cannot find the config.ini file in that folder, but the config.ini file is in the root, where the application.cfc is.  To load the config.ini, I am using:

<!--- Get config file keys for application settings. --->

<cfset lstKeys = evaluate( 'getProfileSections( getDirectoryFromPath( getBaseTemplatePath() ) & "\config.ini" ).#application.vars.environment#' ) />

(The above code is where the error message references)  I'm told the app.cfc transcends down the folder path until another application.cfc is found (I'm not using others), so is the app.cfc running from the /framework/com folder?  is that why it's trying to find a config file at /framework/com/config.ini?

769
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 24, 2010 Aug 24, 2010

I seem to rememeber coming across this before - getBaseTemplatePath() returns the path of the page you called, *not* the root of the site. I tend to set an application-level variable of, say, application.config.siteroot using expandPath(".") in an onApplicationStart method.

Any calls to config files can then be relative to that variable rather than being dynamically generated which, as you've found, can be ropey.

Is there any reason you can't read in the config once at Application start rather than reading files on disk for every page request? That's what I'd do, read once and load into application-level structs - it should then be much more efficient depending on what you're doing.

O.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 24, 2010 Aug 24, 2010

I'm sorry if I mislead in my original message, but I am loading the config.ini in the onApplicationStart (this is why I'm confused as to why this code is executing again when I make my AJAX request - not only is it running onApplicationStart, but it's doing so assuming the now current location of /framework/com is the "root" (and it's not).

Basically, every key in my config file becomes a variable and value in a structure called application.vars.  So if the config.ini has an entry of:

absoluteRootURL=http://www.domain.com/folder

Then I'll have:

application.vars.absoluteRootURL (and it'll be set to 'http://www.domain.com/folder')

I tested this by dumping in onApplicationStart, and the structure is created as expected.  I just can't figure out why onApplicationStart is being recalled during this AJAX.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 24, 2010 Aug 24, 2010

FYI, I also have:

application.vars.absoluteRootPath = "\\servername\c$\inetpub\wwwroot\folder"

So I can absolutely reference any folder/file in the application via a URL forward slash pathing or local system backslash pathing.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 24, 2010 Aug 24, 2010

Hey, I looked up the documentation on expandPath (never knew it could accept so many differently formatted parameters), but I took out the get functions and used "expandPath( '\' )" and now tha AJAX is working perfectly!

I appreciate the help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 24, 2010 Aug 24, 2010
LATEST

No worries, there are a vast array of functions in CF which can all seem to have the same purpose, but as you've found they don't all work entirely as expected!

Glad you got it sorted.

O.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources