Configuration
package()
Signature
Section titled “Signature”package() — returns struct
Available in: mapper
Category: Routing
Description
Section titled “Description”Scopes the controllers for any routes defined inside its block to a specific subfolder (package) without adding the package name to the URL. This is useful for organizing your controllers in subfolders while keeping the URL structure clean.
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>
mapper()
.package("public")
// Example URL: /products/1234
// Controller: public.Products
.resources("products")
.end()
// Example URL: /users/4321
// Controller: Users
.resources(name="users", nested=true)
// Calling `package` here is useful to scope nested routes for the `users`
// resource into a subfolder.
.package("users")
// Example URL: /users/4321/profile
// Controller: users.Profiles
.resource("profile")
.end()
.end()
.end();
</cfscript>