Return to v2.5.0 docs

get()


Configuration Routing struct mapper


Create a route that matches a URL requiring an HTTP GET method. We recommend only using this matcher to expose actions that display data. See post, patch, delete, and put for matchers that are appropriate for actions that change data in your database.

Name Type Required Default Description
name string No Camel-case name of route to reference when build links and form actions (e.g., blogPost).
pattern string No Overrides the URL pattern that will match the route. The default value is a dasherized version of name (e.g., a name of blogPost generates a pattern of blog-post).
to string No Set controller##action combination to map the route to. You may use either this argument or a combination of controller and action.
controller string No Map the route to a given controller. This must be passed along with the action argument.
action string No Map the route to a given action within the controller. This must be passed along with the controller argument.
package string No Indicates a subfolder that the controller will be referenced from (but not added to the URL pattern). For example, if you set this to admin, the controller will be located at admin/YourController.cfc, but the URL path will not contain admin/.
on string No If this route is within a nested resource, you can set this argument to member or collection. A member route contains a reference to the resource's key, while a collection route does not.
redirect string No Redirect via 302 to this URL when this route is matched. Has precedence over controller/action. Use either an absolute link like /about/, or a full canonical link.
<cfscript>

mapper()
    // Route name:  post
    // Example URL: /posts/my-post-title
    // Controller:  Posts
    // Action:      show
    .get(name="post", pattern="posts/[slug]", to="posts##show")

    // Route name:  posts
    // Example URL: /posts
    // Controller:  Posts
    // Action:      index
    .get(name="posts", controller="posts", action="index")

    // Route name:  authors
    // Example URL: /the-scribes
    // Controller:  Authors
    // Action:      index
    .get(name="authors", pattern="the-scribes", to="authors##index")

    // Route name:  commerceCart
    // Example URL: /cart
    // Controller:  commerce.Carts
    // Action:      show
    .get(name="cart", to="carts##show", package="commerce")

    // Route name:  extranetEditProfile
    // Example URL: /profile/edit
    // Controller:  extranet.Profiles
    // Action:      edit
    .get(
        name="editProfile",
        pattern="profile/edit",
        to="profiles##edit",
        package="extranet"
    )

    // Example scoping within a nested resource
    .resources(name="users", nested=true)
        // Route name:  activatedUsers
        // Example URL: /users/activated
        // Controller:  Users
        // Action:      activated
        .get(name="activated", to="users##activated", on="collection")

        // Route name:  preferencesUsers
        // Example URL: /users/391/preferences
        // Controller:  Preferences
        // Action:      index
        .get(name="preferences", to="preferences##index", on="member")
    .end()
.end();

</cfscript>

Related Functions

Routing