Skip to content

Instantly share code, notes, and snippets.

@cdtweb
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdtweb/5f96296ca58f8df3ca8c to your computer and use it in GitHub Desktop.
Save cdtweb/5f96296ca58f8df3ca8c to your computer and use it in GitHub Desktop.
RESTful remap method for CodeIgniter controllers
<?php
/**
* RESTful remap method for CodeIgniter controllers
*
* @author Clint Tyler <ctyler@cdtwebsolutions.com>
*/
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