Skip to content

Controller

isGet()

isGet() — returns boolean

Available in: controller Category: Miscellaneous Functions

Checks if the current HTTP request method is GET. Useful for controlling logic depending on whether a page is being displayed or data is being requested via GET.

component extends="Controller" {

    public void function show() {
        if (isGet()) {
            // Display a form or data
            post = model("Post").findByKey(params.id);
            renderWith(action="show", data=post);
        } else {
            // Handle non-GET request (e.g., POST, DELETE)
            flashInsert(error="Invalid request method.");
            redirectTo(action="index");
        }
    }

}