Peter Amiri
02/03/2022, 3:49 PMbox
mkdir testURLFor --cd
install cfwheels-template-hellopages
Now start your server. You'll see a page one that has some links to page two which has some links to page three and then back to one. There are three sets of links on each page, the first uses a named route, the second specifies just an action, and the third specifies the controller and action. You'll see this links work fine and you can navigate to the next page using any of the links. Now go to your address bar and specifically go to /index.cfm/wildcard/one
you'll see a similar page with links to get you to the next page. I turn the first link into a static text cause we don't have named routes for the wildcard controller. Now you see the wildcard links are broken. They only contain the controller name. It's not the routing engine cause you can go to the address bar and enter /index/wildcard/two
and /index.cfm/wildcard/three
and the proper page comes up but the link that are built by the LinkFor() function are broken.
Now go into /wheels/global/misc.cfm
and comment out the else if block on line 669-672. Now reload your app and visit /index.cfm/wildcard/one
and you'll see the wildcard links built by specifying only the action or the controller and action now work.neokoenig
02/03/2022, 4:01 PMneokoenig
02/03/2022, 4:13 PMPeter Amiri
02/03/2022, 4:37 PMDavid Belanger
02/04/2022, 9:53 PMDavid Belanger
03/02/2022, 1:31 PMDavid Belanger
03/02/2022, 1:35 PMDavid Belanger
03/02/2022, 1:36 PMDavid Belanger
03/02/2022, 1:40 PMIt's not the routing engine cause you can go to the address bar and enterI'm not sure I agree with that. You would have to check the params that are generated by the router on all 3 calls (and/index/wildcard/two
and the proper page comes up but the link that are built by the LinkFor() function are broken./index.cfm/wildcard/three
/index.cfm/wildcard/one
, /index.cfm/wildcard/two
and /index.cfm/wildcard/three
)Peter Amiri
03/02/2022, 5:44 PMwildcard
.
I can submit a PR if you agree with my assesment.David Belanger
03/03/2022, 6:46 PMPeter Amiri
03/04/2022, 4:24 PM<cfscript>
// Use this file to add routes to your application and point the root route to a controller action.
// Don't forget to issue a reload request (e.g. reload=true) after making changes.
// See <http://docs.cfwheels.org/docs/routing> for more info.
mapper()
.get(name="one", pattern="one/", to="main##one")
.get(name="two", pattern="two/", to="main##two")
.get(name="three", pattern="three/", to="main##three")
// The "wildcard" call below enables automatic mapping of "controller/action" type routes.
// This way you don't need to explicitly add a route every time you create a new action in a controller.
.wildcard(mapKey = true)
// The root route below is the one that will be called on your application's home page (e.g. <http://127.0.0.1/>).
// You can, for example, change "wheels##wheels" to "home##index" to call the "index" action on the "home" controller instead.
.root(to = "main##one", method = "get")
.end();
</cfscript>
So you see that the only routes being defined are the three routes in the main controller, the wildcard route, and the root route.
Here is the directory structure of the views directory:
āāā helpers.cfm
āāā home
ā āāā _dumps.cfm
ā āāā one.cfm
ā āāā three.cfm
ā āāā two.cfm
āāā layout.cfm
āāā main
āāā _dumps.cfm
āāā one.cfm
āāā three.cfm
āāā two.cfm
This is the contents of the _dumps.cfm partial:
<cfdump var="#params#" label="params">
<cfdump var="#urlFor(route='two')#" label="urlFor(route='two')">
<cfdump var="#urlFor(action='two')#" label="urlFor(action='two')">
<cfdump var="#urlFor(controller='home',action='two')#" label="urlFor(controller='home',action='two')">
<cfdump var="#urlFor(route='two',controller='home',action='one')#" label="urlFor(route='two',controller='home',action='two')">
So on each page I dump the params structure as well as what urlFor would return if one specifies a route name, an action only, a controller and an action, and finally a route, controller, action combination. I've attached some screen shots that show me calling the six different pages by manipulating the URL line by calling the pages via named routes and wildcard routes.
You will see that if the named route is used either by itself or in a triple combination with the controller and action then the url for the route is returned. But if the action only or the controller and action are defined then the returned URL is often invalid.Peter Amiri
03/04/2022, 6:05 PM<cfscript>
// Use this file to add routes to your application and point the root route to a controller action.
// Don't forget to issue a reload request (e.g. reload=true) after making changes.
// See <http://docs.cfwheels.org/docs/routing> for more info.
mapper()
.get(name="oneRoute", pattern="onePattern/", to="main##one")
.get(name="twoRoute", pattern="twoPattern/", to="main##two")
.get(name="threeRoute", pattern="threePattern/", to="main##three")
// The "wildcard" call below enables automatic mapping of "controller/action" type routes.
// This way you don't need to explicitly add a route every time you create a new action in a controller.
.wildcard(mapKey = true)
// The root route below is the one that will be called on your application's home page (e.g. <http://127.0.0.1/>).
// You can, for example, change "wheels##wheels" to "home##index" to call the "index" action on the "home" controller instead.
.root(to = "main##one", method = "get")
.end();
</cfscript>
And here are the screen shots. I think you'll see that in all instances the returned URL is a valid functioning URL.