Question

CFWheels has the URLFor() function for getting the internal URL based on supplied arguments. Is there a way to get the internal URL without supplying any arguments?

For example: Given a user navigates to "http://somedomain.com" or "http://somedomain.com/about/" or "http://somedomain.com/contact/" is there a method like ReWrittenURL() that returns something like "/" or "/about/" or "/contact/"?

Using URLFor() with no arguments returns "/home/index" or "/about/index" or "/contact/index".

CGI.SCRIPT_NAME returns "/rewrite.cfm"

Obviously with Javascript using document.location.href I can get what I'm after.

Was it helpful?

Solution

Does CGI.path_info have the value you're looking for?

edit

At first, I deleted this post, being utterly confounded. Now I've done a little test - I downloaded the latest wheels core files (1.1.6), extracted to an IIS 7.5 (with URL Rewrite module installed) + CF9 webserver, and edited the "web.config" file in the core root, setting "enabled='true'" for the rewrite rule. Also, since I was running this example from a subfolder, I changed the path from "/rewrite.cfm" to just "rewrite.cfm". This got me to the point where I was able to successfully requests urls like this:

http://server/wheelstest/wheels/wheels

From here, I edited the layout.cfm under views/wheels, adding:

<cfdump var="#cgi#">

When I then request the above URL (/wheelstest/wheels/wheels), I see the dump for the cgi scope. Under path_info, this is the value: /wheels/wheels.

Next, I added a blank "index.cfm" file under views/wheels.

When I request /wheelstest/wheels, I get this for path_info: "/wheels".

When I request /wheelstest/wheels/, I get this for path_info: "/wheels/".

When I request /wheelstest/wheels/index, I get this for path_info: "/wheels/index".

When I request /wheelstest/wheels/index/, I get this for path_info: "/wheels/index/".

So basically - cgi.path_info is doing for me exactly what you describe you want. What is different about your setup than mine, such that it isn't returning that value for you?

OTHER TIPS

there might be a better way to do this... but here I go anyway

every page gets sent the #params#

    <cfdump var="#params#">
    <cfoutput>#params.action#/#params.controller#/#params.key#</cfoutput>
    <cfabort>

try putting that in a controller and see the results

the problem is that if the objects inside the params object don't exist you get an error. So the path that gets generated needs to check if the struct key exists and edit accordingly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top