Skip to content

Instantly share code, notes, and snippets.

@Kindari
Created October 10, 2012 22:02
Show Gist options
  • Select an option

  • Save Kindari/3868762 to your computer and use it in GitHub Desktop.

Select an option

Save Kindari/3868762 to your computer and use it in GitHub Desktop.
Numeric arguments to controllers pass to index method
<?php
class News_Controller extends Base_Controller
{
public $restful = true;
public function __call($name, $args)
{
$matches = array();
preg_match('/(action|get|put|delete|post)_(\d+)/', $name, $matches);
if ($matches) {
array_unshift($args, $matches[2]); // Shift the number to the beggining of our arguments.
$name = $matches[1] . '_index'; // method to call
}
return call_user_func_array(array($this, $name), $args);
}
public function get_index($id)
{
return $id;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment