show
action on the Products
controller:config/routes.cfm
.end()
.routes.cfm
file can be a handy map, telling you which controller and action to start looking in.GET
, POST
, PATCH
, or DELETE
.POST
, PATCH
, or DELETE
when a given action changes the state of your application's data:POST
PATCH
DELETE
GET
request method.[squareBrackets]
. Parameter values get sent to the controller in the params
struct.key
and slug
are 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 params.key
and params.slug
, respectively.key
is present in the URL but not slug
, then it's the second route above that will match..
is treated as a special characters in patterns and should generally not be used (one exception being when you are responding with multiple formats). If your parameters may have .
in their value, please use the long form URL format: /?controller=[controller_name]&action=[action_name]&[parameter_name]=[parameter_value]
[Reload, View Routes, Run Tests, View Tests]
config/routes.cfm
file, including name, method, pattern, controller, and action.showDebugInformation
setting in the Configuration and Defaults chapter.products
table and want to have a section of our application for managing the products, we can set up the routes using the resources() method like this in config/routes.cfm
:products
controller:PUT
?PUT
or PATCH
HTTP verb. It has been settled mostly that PATCH
is the way to go for most situations. CFWheels resources set up both PUT
and PATCH
to address this confusion, but you should probably prefer linking up PATCH
when you are able.[key]
placeholder in the paths listed above in the Strongly Encouraged: Resource Routing section.)GET
requests to modify resources in your database (i.e., creating, updating, or deleting records). Always require POST
, PUT
, PATCH
, or DELETE
verbs for those sorts of routing endpoints.to="controller##action"
or use separate controller
/action
arguments. The to
argument allows you to delineate controller
and action
within 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).users
resource using these methods like so (though obviously there is little practical reason for doing so):only
or except
arguments:GET
or POST
.PUT
, PATCH
, and DELETE
) in this way:POST
request with aPOST
variable named _method
specifying the specific HTTP verb (e.g., _method=delete
)PATCH
and DELETE
.controllers
folder of your application./admin/products
, and the controller would be stored at controllers/admin/Products.cfc
.package
mapper method:/articles
and /profile
in the URL, but the controllers will be located at controllers/public/Articles.cfc
and controllers/public/Profiles.cfc
, respectively.customer
and its children appointment
records.config/routes.cfm
:appointments
resource 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 key
ID.[controller]/[action]/[key]
. The convention for URLs was as follows:show
action in the news
controller. It also passed a parameter called key
to the action, with a value of 5
.[controller]/[action]
, however, because resources and the other routing methods are more appropriate for working with records identified by primary keys.wildcard
generates:wildcard
method by default will only generate routes for the GET
request method. If you would like to enable other request methods on the wildcard, you can pass in the method
or methods
argument:method
argument to wildcard
with anything other than get
gives you the potential to accidentally expose a route that could change data in your application with a GET
request. This opens your application to Cross Site Request Forgery (CSRF) vulnerabilities.wildcard
is provided for convenience. Once you're comfortable with routing concepts in CFWheels, we strongly recommend that you use resources (resources
, resource
) and the other verb-based helpers (get
, post
, patch
, put
, and delete
) listed above instead.config/routes.cfm
file./users/promoted
, this will load the show
action of the users
controller because that was the first pattern that was matched by the CFWheels router./welcome-to-the-site
and /terms-of-use
handled by the same controller and action. Here's what you can do to achieve this.config/routes.cfm
that catches all pages like this:/welcome-to-the-site
, this route will be triggered and the show
action will be called on the pages
controller with params.title
set to welcome-to-the-site
.config/routes.cfm
file looking something like this:products
and sessions
are 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/1/
and /users/bob/
go to different controller actions.key
argument being made of digits only will apply to all the nested resourcesanything/you/want
you gets set to the params.username
including the /
's. The second example would require /search/
to be on the end of the URL/articles/[articleKey]/comments/[key]
index
, create
and new
RESTful actions with the ArticleKey
in the URL, but then separate out edit
, show
, update
and delete
actions 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.index
, new
and create
with the /articles/[articleKey]/
part in the URL, but to show
, edit
, update
or delete
a comment, we can just fall back to /comments/
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/preview
is an example of a member route, because it acts on (and displays) a single object.photos/search
is an example of a collection route, because it acts on (and displays) a collection of objects.redirect
argument on GET
, POST
, PUT
, PATCH
, and DELETE
requests. This will execute before reaching any controllers, and perform a 302
redirect immediately after the route is matched..[format]
routes when using resources()
. You may wish to disable this behaviour to trim down the number of generated routes for clarity and performance reasons (or you just don't use this feature!).mapFormat = false
on a per resource basis, or more widely, on a mapper basis: