Configuration
whereIn()
Signature
Section titled “Signature”whereIn() — returns struct
Available in: mapper
Category: Routing
Description
Section titled “Description”Constrain a route variable to only match one of a set of allowed values. Similar to an enum constraint.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
variableName | string | yes | — | The route variable name to constrain. |
values | string | yes | — | A comma-delimited list of allowed values (e.g., "active,inactive,pending"). |
Examples
Section titled “Examples”<cfscript>
mapper()
// 1. Constrain a route variable to a fixed set of allowed string values
// The [status] segment will only match "active", "inactive", or "pending"
.get(name="usersByStatus", pattern="users/[status]", to="users##byStatus")
.whereIn(variableName="status", values="active,inactive,pending")
// 2. Constrain a locale segment to a known list of supported languages
// Requests like /en/home match; /xx/home returns a 404
.get(name="localizedHome", pattern="[locale]/home", to="home##index")
.whereIn(variableName="locale", values="en,fr,de,es")
// 3. Chain whereIn with whereNumber for mixed-type segment constraints
// [type] must be one of the listed values; [id] must be numeric
.get(name="typedItem", pattern="items/[type]/[id]", to="items##show")
.whereIn(variableName="type", values="book,magazine,journal")
.whereNumber("id")
.end();
</cfscript>