showaction on the
routes.cfmfile can be a handy map, telling you which controller and action to start looking in.
DELETEwhen a given action changes the state of your application's data:
[squareBrackets]. Parameter values get sent to the controller in the
slugare parameters that must be present in the URL for the first route to match, and they are required when linking to the route. In the controller, these parameters will be available at
keyis present in the URL but not
slug, then it's the second route above that will match.
[Reload, View Routes, Run Tests, View Tests]
config/routes.cfmfile, including name, method, pattern, controller, and action.
[key]placeholder in the paths listed above in the Strongly Encouraged: Resource Routing section.)
to="controller##action"or use separate
toargument allows you to delineate
actionwithin a single string using a
#separator (which must be escaped as a double
##because of CFML's special usage of that symbol within string syntax).
usersresource using these methods like so (though obviously there is little practical reason for doing so):
DELETE) in this way:
POSTrequest with a
_methodspecifying the specific HTTP verb (e.g.,
controllersfolder of your application.
/admin/products, and the controller would be stored at
/profilein the URL, but the controllers will be located at
customerand its children
appointmentsresource contain a parameter named
customerKey. The parent resource's ID will always be represented by its name appended with
Key. The child will retain the standard
[controller]/[action]/[key]. The convention for URLs was as follows:
showaction in the
newscontroller. It also passed a parameter called
keyto the action, with a value of
[controller]/[action], however, because resources and the other routing methods are more appropriate for working with records identified by primary keys.
wildcardmethod by default will only generate routes for the
GETrequest method. If you would like to enable other request methods on the wildcard, you can pass in the
/users/promoted, this will load the
showaction of the
userscontroller because that was the first pattern that was matched by the CFWheels router.
/terms-of-usehandled by the same controller and action. Here's what you can do to achieve this.
config/routes.cfmthat catches all pages like this:
/welcome-to-the-site, this route will be triggered and the
showaction will be called on the
config/routes.cfmfile looking something like this:
sessionsare your normal controllers. By adding them to the top of the routes file, CFWheels looks for them first. But your catch-all route is more specific than the site root (
/), so your catch-all should be listed before the call to root().
resources()or other individual route call, or can be added as a chained function in it's own right. Constraints allow you to add regex to a route matching pattern, so you could for instance, have
/users/bob/go to different controller actions.
keyargument being made of digits only will apply to all the nested resources
anything/you/wantyou gets set to the
/'s. The second example would require
/search/to be on the end of the URL
newRESTful actions with the
ArticleKeyin the URL, but then separate out
deleteactions into their own, and simpler URL path; When we edit or update a comment, we're doing it on that object as it's own entity, and the relationship to the parent article already exists.
/articles/[articleKey]/part in the URL, but to
deletea comment, we can just fall back to
member()block is used within a nested resource to create routes which act 'on an object'; A member route will require an ID, because it acts on a member.
photos/1/previewis an example of a member route, because it acts on (and displays) a single object.
photos/searchis an example of a collection route, because it acts on (and displays) a collection of objects.
DELETErequests. This will execute before reaching any controllers, and perform a
302redirect immediately after the route is matched.
.[format]routes when using
resources(). You may wish to disable this behavior to trim down the number of generated routes for clarity and performance reasons (or you just don't use this feature!).
mapFormat = falseon a per resource basis, or more widely, on a mapper basis: