Configuration
namespace()
Signature
Section titled “Signature”namespace() — returns struct
Available in: mapper
Category: Routing
Description
Section titled “Description”Scopes any the controllers for any routes configured within this block to a subfolder (package) and also adds the package name to the URL.
Parameters
Section titled “Parameters”| 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. |
Examples
Section titled “Examples”<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()
// Custom package and path: name="foo", package="foos", path="foose"
// The `path` argument overrides the default URL prefix (which would be "foo").
// The `package` argument overrides the default controller subfolder (which would be "foo").
.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>