Welcome Guest, Not a member yet? Register   Sign In
Undefined Function In Controller
#1

[eluser]Lima[/eluser]
Dear All,

Anyone can tell me how to route undefined function in controller to index function?

Code:
class Utils extends Controller {

  function Utils()
  {
    parent::Controller();    
  }

  function index()
  {
    echo "Index";
  }

  function test()
  {
    echo "Test";
  }
}

If someone access url http://www.domain.com/utils/foobar it will show "Page not found".
Now how to route foobar to index function automatically, so it does not show "Page not found" but it will echo "Index".

Thanks.
#2

[eluser]pistolPete[/eluser]
Have a look at the _remap() function:
Code:
public function _remap($method)
{
   if (method_exists($this, $method))
      $this->$method();
   else
     $this->index();
}
#3

[eluser]Lima[/eluser]
Where must I put that function? hook, controller, or where?
#4

[eluser]Lima[/eluser]
Yeah, I do understand.

Important: If your controller contains a function named _remap(), it will always get called regardless of what your URI contains. It overrides the normal behavior in which the URI determines which function is called, allowing you to define your own function routing rules.

Thanks pistolPete




Theme © iAndrew 2016 - Forum software by © MyBB