Search code examples
phpcodeignitercodeigniter-routing

How to reference a function after an argument in CodeIgniter URLs?


My desired URL structure for a section of a web application is as follows:
/user/FooBar42/edit/privacy, and I would like this to route to controller: user, function: edit, with FooBar42 and privacy as arguments (in that order). How should I accomplish this with CodeIgniter?


Solution

  • You can also use the remapping option of the CI controller

    http://ellislab.com/codeigniter/user-guide/general/controllers.html#remapping

    and doing something like this:

    public function _remap($method, $params = array())
    {
        // check if the method exists
        if (method_exists($this, $method))
        {
            // run the method
             return call_user_func_array(array($this, $method), $params);
        }
        else
        {
         // method does not exists so you can call nay other method you want
         $this->edit($params);
        }
    }