Some new convenience functions for the RequestHandler

Published on and tagged with cakephp  feature

Nate has added three new convenience functions to the RequestHandler component (this component is included in the core of CakePHP). The three functions are:

  • isPost()
  • isPut()
  • isGet()

I think these functions are self-explanatory ;-)

One comment baked

  • Nate

    These functions work in conjunction with the new Security component, which allows you to do things like this:

    function beforeFilter( ) {
    $this->Security->requirePost(“list”, “of”, “actions”);
    // -and/or-
    $this->Security->requireAuth(“list”, “of”, “actions”);

    With requirePost, if any action in the list is requested with a non-POST request, it is blackholed (404 and exit).

    With requireAuth, an authentication key is written to the Session and in a param that gets output in a hidden field with any form generated by HtmlHelper.

    When POST’ed this value is compared to the value in the Session, and if it doesn’t match, the request is blackholed.

    The Security component also has a $blackHoleCallback variable, which can be set to the name of a controller method to be called instead of the default Security->blackHole( ).

© daniel hofstetter. Licensed under a Creative Commons License