Return to v2.5.0 docs

namespace()


Configuration Routing struct mapper


Scopes any the controllers for any routes configured within this block to a subfolder (package) and also adds the package name to the URL.

Name Type Required Default Description
name string Yes Name to prepend to child route names.
package string No [runtime expression] Subfolder (package) to reference for controllers. This defaults to the value provided for name.
path string No [runtime expression] Subfolder path to add to the URL.
<cfscript>

mapper()
    .namespace("api")
        .namespace("v2")
            // Route name:  apiV2Products
            // Example URL: /api/v2/products/1234
            // Controller:  api.v2.Products
            .resources("products")
        .end()

        .namespace("v1")
            // Route name:  apiV1Users
            // Example URL: /api/v1/users
            // Controller:  api.v1.Users
            .get(name="users", to="users##index")
        .end()
    .end()

    .namespace(name="foo", package="foos", path="foose")
        // Route name:  fooBars
        // Example URL: /foose/bars
        // Controller:  foos.Bars
        .post(name="bars", to="bars##create")
    .end()
.end();

</cfscript>

Related Functions

Routing