Skip to main content
December 1, 2008
Question

Problem with Java functions within a CFC

  • December 1, 2008
  • 1 reply
  • 298 views
Hi,

I looked on CFLIB for a function that would return the current URL. I found a really neat one which doesn't use the sometimes unreliable cgi variables.

It goes something like this:

<cffunction name="getCurrentURL" hint="Gets the current URL" returntype="string" output="false" access="public">

<cfset var currentURL = getPageContext().getRequest().GetRequestUrl().toString() />

<cfif len(trim(cgi.query_string))>
<cfset currentURL = currentURL & "?" & cgi.query_string />
</cfif>

<cfreturn currentURL />

</cffunction>

If I call this on like a top level index.cfm it works perfectly...however, if I put this function into a CFC, I get an odd string returned looking something like:

cfutils2ecfc1871686742$funcGETCURRENTURL@666b79

There's no error, but the string it sends back is clearly very odd.

Is there a way to use this function within a CFC? I figured it made sense as I would be using something like this quite a lot and don't want to repeat myself.

Many thanks,
Mikey.
    This topic has been closed for replies.

    1 reply

    Inspiring
    December 1, 2008
    a request to a .cfc is a separate request, and thus has its own
    PageContext, which is not same as PageContext of requesting template...

    and what's so unreliable about cgi.script_name???

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/