CodeIgniter Forums
Codeigniter User Guide, Controllers: default_method()? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Codeigniter User Guide, Controllers: default_method()? (/thread-57175.html)



Codeigniter User Guide, Controllers: default_method()? - El Forum - 02-22-2013

[eluser]Unknown[/eluser]
Hello Codeigniter experts!

I'd be grateful to clarification of something on the controllers page of the user guide:

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

The section "Remapping function calls" contains the following snippet:

Code:
public function _remap($method)
{
    if ($method == 'some_method')
    {
        $this->$method();
    }
    else
    {
        $this->default_method();
    }
}

I tried to implement it like this:

Code:
public function _remap($method='comments')
{
  if ($method == 'news')
  {
   $this->$method();
  }
  else
  {
   $this->default_method();
  }
}

Needless to say, I received an error: Call to undefined method Blog::default_method().

What should I do differently?

Thanks in advance!


Codeigniter User Guide, Controllers: default_method()? - El Forum - 02-22-2013

[eluser]InsiteFX[/eluser]
The CI_Controller default method is the index method everything will pass through the index method.

_remap will proccess any parameters that are passed through the index method.

Code:
public function index($prams)
{
    // your code here
}

$prams would be passed to the _remap method.

This is usefull for like a users profile. http://www.your.com/username