Controller
isOptions()
Signature
Section titled “Signature”isOptions() — returns boolean
Available in: controller
Category: Miscellaneous Functions
Description
Section titled “Description”Returns whether the request was an OPTIONS request or not.
Examples
Section titled “Examples”// 1. Respond to a CORS preflight OPTIONS request
if (isOptions()) {
header(name = "Access-Control-Allow-Methods", value = "GET, POST, PUT, DELETE");
renderNothing();
return;
}
// 2. Restrict an action to only handle OPTIONS requests
if (!isOptions()) {
redirectTo(action = "index");
}
// 3. Store the result to use in a conditional
requestIsOptions = isOptions();
// requestIsOptions -> true when the HTTP method is OPTIONS, false otherwise