There are a few ways to specify a method.
- If your client supports it you can use native HTTP methods.
- You can set the HTTP-X-Method-Override header.
- You can submit an input with the name _method
Any of these 3 approaches can be used to set the HTTP method used
by CakePHP internally, and will effect the result of this method.
public function handle() { if ($this->_logger instanceof Syncroton_Log) { $this->_logger->debug(__METHOD__ . '::' . __LINE__ . ' REQUEST METHOD: ' . $this->_request->method()); } switch ($this->_request->method()) { case 'OPTIONS': $this->_handleOptions(); break; case 'POST': $this->_handlePost(); break; case 'GET': header("MS-Server-ActiveSync: 14.00.0536.000"); echo "It works!<br>Your userid is: {$this->_userId} and your IP address is: {$_SERVER['REMOTE_ADDR']}."; break; } }
/** * Test the method() method. * * @return void */ public function testMethod() { $_SERVER['REQUEST_METHOD'] = 'delete'; $request = new CakeRequest('some/path'); $this->assertEquals('delete', $request->method()); }
/** * @param $data * * @return mixed */ protected function _get_request($data) { $request = new CakeRequest(); $data['request_user_agent'] = $request::header('User-Agent'); $data['request_client_ip'] = $request->clientIp(); $data['request_method'] = $request->method(); $data['request_referer'] = $request->referer(); $data['request_url'] = Router::url(null, true); return $data; }