Copy link to clipboard
Copied
Can you put onRequestStart something like this so it loads the correct header.cfm? (yes this sample is setting a variable I know for a header I would have to use include)
At the moment on the pages show 5 and I am not sure why. Does it not know that page path that is being requested?
<cfset currentPath = getCurrentTemplatePath()>
<cfif findnocase("end", currentPath) GT 0>
<cfset request.xyz = 1>
<cfelseif findnocase("start", currentPath) GT 0>
<cfset request.xyz = 2>
<cfelse>
<cfset request.xyz = 5>
</cfif>
I suspect you're after the getBaseTemplatePath() function.
Copy link to clipboard
Copied
Why don't you try outputting getCurrentTemplatePath() to find out?
Copy link to clipboard
Copied
ok so when output getCurrentTemplatePath() I get the correct path however it does not see the "end" or "start" in it and I am not sure why. Any ideas?
Copy link to clipboard
Copied
Personally I'd try outputting findNoCase("end", currentPath) to the screen and hitting the various pages, see what you come up with.
Copy link to clipboard
Copied
ok this is really weird. That works too but it never sets the request.xyz to anything other than 5. findNoCase is not 0 in any case. I dont understand that.
Copy link to clipboard
Copied
Okay, well try doing a <cfdump var="#request#" /> after the cfif statement. Where are you trying to reference the request.xyz variable?
Copy link to clipboard
Copied
I am trying to reference it on the individual pages. ok I found the problem. The currentpath is to the application not to the page being requested. So how do I get it to set it to the page being requested?
Copy link to clipboard
Copied
I suspect you're after the getBaseTemplatePath() function.
Copy link to clipboard
Copied
Owain Thank you so much. That is what I was looking for.
Copy link to clipboard
Copied
Excellent, I thought it'd be that. Just goes to show you should never *assume* you know what's going on, *know* what's going on
Copy link to clipboard
Copied
TheScarecrow wrote:
Owain Thank you so much. That is what I was looking for.
What? To match the "start" in onRequestStart?
Copy link to clipboard
Copied
The OP has never suggested he's trying to do that, I don't see why you'd ever have a header at the end of a page.
Copy link to clipboard
Copied
Owain North wrote:
The OP has never suggested he's trying to do that, I don't see why you'd ever have a header at the end of a page.
Header for onRequestStart, footer for onRequestEnd, and the expectation that the value of request.xyz should be 1 or 2, the implicit logic is all there. However, I agree with you it's only implicit, mostly padded by my imagination.
Copy link to clipboard
Copied
Yes The code should have been.
<cfset currentPath = getBaseTemplatePath()>
<cfif findnocase("end", currentPath) GT 0>
<cfset request.xyz = 1>
<cfelseif findnocase("start", currentPath) GT 0>
<cfset request.xyz = 2>
<cfelse>
<cfset request.xyz = 5>
</cfif>
Copy link to clipboard
Copied
TheScarecrow wrote:
Yes The code should have been.
<cfset currentPath = getBaseTemplatePath()>
<cfif findnocase("end", currentPath) GT 0>
<cfset request.xyz = 1>
<cfelseif findnocase("start", currentPath) GT 0>
<cfset request.xyz = 2>
<cfelse>
<cfset request.xyz = 5>
</cfif>
Fair enough. I would suggest instead
<cffunction name="onRequestStart">
<cfargument name = "targetPage" type="String" required="true">
<!--- Relative path: path from web root to requested page.--->
<!--- <cfset currentPath = arguments.targetPage> --->
<!--- Absolute path--->
<cfset currentPath = expandPath(arguments.targetPage)>
</cffunction>
Copy link to clipboard
Copied
You would suggest a mandatory argument in onRequestStart? From where would that argument get passed?
Copy link to clipboard
Copied
Dan Bracuk wrote:
You would suggest a mandatory argument in onRequestStart? From where would that argument get passed?
I don't suggest it, ColdFusion does. The argument gets passed by the caller of onRequestStart, namely, ColdFusion.
Copy link to clipboard
Copied
TheScarecrow wrote:
Can you put onRequestStart something like this so it loads the correct header.cfm? (yes this sample is setting a variable I know for a header I would have to use include)
At the moment on the pages show 5 and I am not sure why. Does it not know that page path that is being requested?
<cfset currentPath = getCurrentTemplatePath()>
<cfif findnocase("end", currentPath) GT 0>
<cfset request.xyz = 1>
<cfelseif findnocase("start", currentPath) GT 0>
<cfset request.xyz = 2>
<cfelse>
<cfset request.xyz = 5>
</cfif>
I hope you're not expecting this code to tell you whether you're in onRequestStart or in onRequestEnd. OnRequestStart and onRequestEnd are methods in Application.cfc. They cannot be accessed using getCurrentTemplatePath().
If you put getCurrentTemplatePath() in OnRequestStart, it will register the path to your Application.cfc file. Your code will then register the value request.xyz = 1 or 2 only if the path to your application file contains "start" or "end". For example,
C:\ColdFusion9\wwwroot\workspace\render\Application.cfc
C:\ColdFusion9\wwwroot\startDir\Application.cfc