« Return to Thread: $this->getRequest()->isPost() vs. ($_SERVER['REQUEST_METHOD'] == 'POST')

Re: $this->getRequest()->isPost() vs. ($_SERVER['REQUEST_METHOD'] == 'POST')

by HMunroe :: Rate this Message:

Reply to Author | View in Thread

Matthew Weier O'Phinney-3 wrote:
First, you _can_ use the $_request property directly. However, if you
ever modify getRequest() in your class or in a custom base controller
class, then you may be accessing the wrong property or overriding
necessary business logic. For this reason, we recommend using
getRequest() to grab the request object. (This is good OOP practice,
btw.)
I understand that, and I am OK with it (and I welcome all the new features added like the params stuff), but the example I gave is with $_SERVER and not $_REQUEST. And it is a good OOP practice, but in this case is a way too much for something so simple.

Matthew Weier O'Phinney-3 wrote:
Next, using isPost() is more portable than using
$_SERVER['REQUEST_METHOD']. The reasons are that your web server may or
may not populate this environment variable, and for testing. With
testing, we allow you to specifically set the request method -- $_SERVER
is never modified in this case. This gives you the ability to test your
applications without needing a web server involved.
I see, it's cool.

 « Return to Thread: $this->getRequest()->isPost() vs. ($_SERVER['REQUEST_METHOD'] == 'POST')