Skip to content

Commit 22536c3

Browse files
Added option of emulating the request-method. This is for example used by MooTools in the Request-class.
Changes: - added config option (enable_emulate_request) - modified _detect_method() to allow emulated methods - moved loading the config file to beginning of __construct(), before $this->request->method is set
1 parent c2a26a1 commit 22536c3

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

application/config/rest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@
1212
*/
1313
$config['rest_default_format'] = 'xml';
1414

15+
/*
16+
|--------------------------------------------------------------------------
17+
| Enable emulate request
18+
|--------------------------------------------------------------------------
19+
|
20+
| Should we enable emulation of the request (e.g. used in Mootools request)?
21+
|
22+
| Default: false
23+
|
24+
*/
25+
$config['enable_emulate_request'] = TRUE;
26+
27+
1528
/*
1629
|--------------------------------------------------------------------------
1730
| REST Realm

application/libraries/REST_Controller.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ public function __construct()
3030
{
3131
parent::__construct();
3232

33-
// How is this request being made? POST, DELETE, GET, PUT?
34-
$this->request->method = $this->_detect_method();
35-
3633
// Lets grab the config and get ready to party
3734
$this->load->config('rest');
3835

36+
// How is this request being made? POST, DELETE, GET, PUT?
37+
$this->request->method = $this->_detect_method();
38+
3939
$this->load->library('security');
4040
if ($this->config->item('rest_auth') == 'basic')
4141
{
@@ -295,6 +295,12 @@ private function _detect_format()
295295
private function _detect_method()
296296
{
297297
$method = strtolower($this->input->server('REQUEST_METHOD'));
298+
299+
if ($this->config->item('enable_emulate_request') && $this->input->post('_method'))
300+
{
301+
$method = $this->input->post('_method');
302+
}
303+
298304
if (in_array($method, array('get', 'delete', 'post', 'put')))
299305
{
300306
return $method;

0 commit comments

Comments
 (0)