Return to v2.5.0 docs

resources()


Configuration Routing struct mapper


Create a group of routes that exposes actions for manipulating a collection of resources. A plural resource exposes URL patterns for the entire CRUD lifecycle (index, show, new, create, edit, update, delete), exposing a primary key in the URL for showing, editing, updating, and deleting records. If you need to generate routes for manipulating a singular resource without a primary key, see the resource mapper method.

Name Type Required Default Description
name string Yes Camel-case name of resource to reference when build links and form actions. This is typically a plural word (e.g., posts).
nested boolean No false Whether or not additional calls will be nested within this resource.
path string No [runtime expression] Override URL path representing this resource. Default is a dasherized version of name (e.g., blogPosts generates a path of blog-posts).
controller string No Override name of the controller used by resource. This defaults to the value provided for name.
singular string No Override singularize() result in plural resources.
plural string No Override pluralize() result in singular resource.
only string No Limits the list of RESTful routes to generate. Can include index, show, new, create, edit, update, and delete.
except string No Excludes RESTful routes to generate, taking priority over the only argument. Can include index, show, new, create, edit, update, and delete.
shallow boolean No Turn on shallow resources.
shallowPath string No Shallow path prefix.
shallowName string No Shallow name prefix.
constraints struct No Variable patterns to use for matching.
mapFormat boolean No [runtime expression] Whether or not to add an optional .[format] pattern to the end of the generated routes. This is useful for providing formats via URL like json, xml, pdf, etc.
<cfscript>

mapper()
    // With default arguments
    .resources("admins")

    // Point authors URL to controller at `controllers/Users.cfc`
    .resources(name="authors", controller="users")

    // Limited list of routes generated by `only` argument.
    .resources(name="products", only="index,show,edit,update")

    // Limited list of routes generated by `except` argument.
    .resources(name="orders", except="delete")

    // Nested resources
    .resources(name="stories", nested=true)
      .resources("heroes")
      .resources("villains")
    .end()

    // Overridden `path`
    .resources(name="blogPostsOptions", path="blog-posts/options")
.end();

</cfscript>

Related Functions

Routing