| Subcribe via RSS

Remap function for CodeIgniter

July 26th, 2009 Posted in Bin

I got tired of looking for this code in other projects so I wanted a handy place to keep it.

PHP:
  1. <?php
  2. function _remap($method)
  3. {
  4.     if (method_exists($this, $method)){
  5.         $this->$method($this->uri->segment(3));
  6.     } else {
  7.         $this->index($method);
  8.     }
  9. }
  10. ?>

In case you're wondering, this function is a reserved method in CodeIgniter controllers that will allow for a dynamic method name to be passed into the URL. Docs on it are here: codeigniter.com/user_guide/general/controllers.html#remapping.

2 Responses to “Remap function for CodeIgniter”

  1. Allan Says:

    Thanks man, this remap method save my life! :)
    really thanks!


  2. Michael Tracey Says:

    Thanks, I was just looking for this. About to write it myself, and did one last google search, and boom.. you wrote it for me. Works like a champ.

    I will mention, in my case, I had to catch real 404′s in the function in the else statement and call show_404() if the input isn’t valid. (I’m using this to call a search if there’s no controller function for the exact URL).

    Appreciate it, keep up the good work.


Leave a Reply

Preview: