01-15-2010, 06:28 AM
[eluser]DieterStruik[/eluser]
Hi CI-ers,
You probably ran across the same problem like me. Trying to avoid the standard 404 page which doesn't include all the CI functionality. Therefore making weird includes, cURL calls etc...
I make use of a language segment in my URI's. Like /en/home. So I needed to route like:
You don't need to change any existing functionality. Put this code below in any controller (I usually extend my main controller). It's the native _remap() method which always get called first. Here you can check stuff like a missing method.
I hope this will be usefull for some of you. I haven't checked it for different types of errors. Just thought about a missing method call. Please let me know anything better.
Hi CI-ers,
You probably ran across the same problem like me. Trying to avoid the standard 404 page which doesn't include all the CI functionality. Therefore making weird includes, cURL calls etc...
I make use of a language segment in my URI's. Like /en/home. So I needed to route like:
Code:
$route['default_controller'] = 'site';
$route['scaffolding_trigger'] = '';
// When first segment is set proceed normally (language checking done in controller)
$route['(\w{2})/(.+)'] = '$2';
// Catch all (important for 404 and language checking)
$route[':any'] = $route['default_controller'];
You don't need to change any existing functionality. Put this code below in any controller (I usually extend my main controller). It's the native _remap() method which always get called first. Here you can check stuff like a missing method.
Code:
public function _remap($method)
{
// Check if method exists.
if (!method_exists($this, $method))
{
// Show custom embedded 404 page.
return;
}
// Else call the method with the arguments passed by CI.
$args = array_slice($this->uri->segment_array(), 3);
return call_user_func_array(array($this, $method), $args);
}
I hope this will be usefull for some of you. I haven't checked it for different types of errors. Just thought about a missing method call. Please let me know anything better.