Skip to content

Configuration

wildcard()

wildcard() — returns struct

Available in: mapper Category: Routing

Special wildcard matching generates routes with `

NameTypeRequiredDefaultDescription
methodstringnogetList of HTTP methods (verbs) to generate the wildcard routes for. We strongly recommend leaving the default value of get and using other routing mappers if you need to POST to a URL endpoint. Pass an empty string to generate the wildcard routes for all verbs (get, post, put, patch, and delete).
actionstringnoindexDefault action to specify if the value for the [action] placeholder is not provided.
mapKeybooleannofalseWhether or not to enable a [key] matcher, enabling a [controller]/[action]/[key] pattern.
mapFormatbooleannofalseWhether 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.
methodsstringno—Alias for method, provided for better readability when listing multiple methods. Takes precedence over method when both are passed.
<cfscript>

mapper()
    // 1. Basic wildcard: enables `[controller]` and `[controller]/[action]`
    //    patterns via GET requests only.
    .wildcard()

    // 2. Also enable a `[controller]/[action]/[key]` pattern.
    .wildcard(mapKey=true)

    // 3. Add an optional `.[format]` suffix to every generated pattern,
    //    e.g. `[controller]/[action].json`.
    .wildcard(mapFormat=true)

    // 4. Change the default action when only `[controller]` is matched.
    //    Requests to `/photos` will route to `photos##home` instead of
    //    `photos##index`.
    .wildcard(action="home")

    // 5. Allow additional HTTP methods beyond GET.
    //    Note: opening up extra methods can create security holes unless
    //    you use `verifies` in your controller to guard data-changing actions.
    .wildcard(method="get,post")
.end();

</cfscript>