CodeIgniter Forums
redirect to index if function not exist - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: redirect to index if function not exist (/showthread.php?tid=27836)



redirect to index if function not exist - El Forum - 02-22-2010

[eluser]cjaffar[/eluser]
i know this may hav been answered but i am having a problem following the solutions provided.

can somebody help in this specific situation using this specific logic:
i hav an app. i am adding a _remap function to catch nonexistent functions. problem is how do i pass the parameters to the called method. method below strangely does not work. check this:

function _remap($method) {
if(!(in_array($method, get_class_methods($this))))
{
$this->index();
} else
{
$methodArguments = implode(',', array_slice($this->uri->segment_array(), 2));
$this->$method($methodArguments);
}
}
}


redirect to index if function not exist - El Forum - 02-22-2010

[eluser]Jelmer[/eluser]
First of all, the method for check if a function exist is kinda strange as there's a simple function for checking that:
Code:
if ( ! method_exists($this, $method))

And to the second part: whether it's a string or an array, it still is just one variable. Why don't you just use the segment_array() within your functions if you want to call them like this?

EDIT:
Or this might also work:
Code:
call_user_func_array(array($this, $method), array_slice($this->uri->segment_array(), 2));



redirect to index if function not exist - El Forum - 02-22-2010

[eluser]cjaffar[/eluser]
thanks lab assistant for that method. i think i got confused while trying different methods of coming up with that 1.

regarding second part, i have my methods receiving 2 or 3 variables which i want separated by commas. strange thing is y wudn't an implode work ?? any other easy ways ??