Created
October 10, 2012 22:02
-
-
Save Kindari/3868762 to your computer and use it in GitHub Desktop.
Numeric arguments to controllers pass to index method
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 | |
| 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