Last active
August 29, 2015 14:03
-
-
Save cdtweb/5f96296ca58f8df3ca8c to your computer and use it in GitHub Desktop.
RESTful remap method for CodeIgniter controllers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* RESTful remap method for CodeIgniter controllers | |
* | |
* @author Clint Tyler <[email protected]> | |
*/ | |
class MY_Controller extends CI_Controller | |
{ | |
public function _remap($method, $arguments = array()) | |
{ | |
$requestMethod = strtolower($this->input->server('REQUEST_METHOD')); | |
if($method == 'index'){ | |
$callMethod = strtolower($requestMethod); | |
}else{ | |
$callMethod = $requestMethod . ucfirst($method); | |
} | |
if(method_exists($this, $callMethod)){ | |
return call_user_func_array(array($this, $callMethod), $arguments); | |
} | |
throw new \BadMethodCallException("{$callMethod} does not exist!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment