Configuration
package()
Signature
Section titled “Signature”package() — 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) without adding 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. |
Examples
Section titled “Examples”<cfscript>
// 1. Scope controllers into a subfolder without adding the package name to the URL
mapper()
.package("admin")
// Route name: adminProducts
// Example URL: /products (no "admin" in the URL)
// Controller: admin.Products
.resources("products")
// Example URL: /users (no "admin" in the URL)
// Controller: admin.Users
.resources("users")
.end()
.end();
// 2. Use the `package` argument to override the subfolder name
mapper()
.package(name="v2", package="api/v2")
// Route name: v2Articles
// Example URL: /articles
// Controller: api/v2.Articles
.resources("articles")
.end()
.end();
// 3. Nest a `package` inside a resource to scope sub-resource controllers
mapper()
.resources(name="users", nested=true)
// Calling `package` here scopes nested routes to a subfolder without
// changing the URL structure.
.package("users")
// Route name: usersProfile
// Example URL: /users/4321/profile
// Controller: users.Profiles
.resource("profile")
.end()
.end()
.end();
</cfscript>