Welcome Guest, Not a member yet? Register   Sign In
404_override ?
#1

[eluser]quasiperfect[/eluser]
can anyone be so nice to explain the new
Code:
$route['404_override'] = 'route';

i placed it in config/routes.php but it doesn't do anything (i use ci2 so no problem about versions)

it handles 404 errors or what's the idea behind ?
#2

[eluser]mddd[/eluser]
The idea is that it allow you to handle a "not found" request before it actually shows the error.
Imagine this situation: you have a site with controllers for several parts: www.example.com/about-us, www.example.com/sign-up, whatever.
But you also want dynamic addresses for your projects: www.example.com/project1, www.example.com/other-project.
These are NOT controllers; they need to be built from the database!
Normally these urls would give a 404 error because there is no 'project1' controller or 'other-project' controller.
Now, with this route, you can send the request to a specific controller. Say $route['404_override'] = 'project';
In that controller, you can check if the requested url ('project1') is indeed a valid project name. If so, display your page. If not, you can still throw the 404 error yourself or show a 'project not found' page.

NOTE: You need to specify a controller AND method you want to have called! So it should read : $route['404_override'] = 'project/show' or something like that. Without a controller AND method, it doesn't work.
#3

[eluser]quasiperfect[/eluser]
thanks mddd for responding
my mistake was that i didn't add a method

now all i miss is a error method / controller
i see that if the controller exists $route['404_override'] doesn't get used
#4

[eluser]bema2004sw[/eluser]
[quote author="quasiperfect" date="1282311195"]thanks mddd for responding
my mistake was that i didn't add a method

now all i miss is a error method / controller
i see that if the controller exists $route['404_override'] doesn't get used[/quote]


Use this:
Code:
$route['404']

because you use HMVC.
#5

[eluser]yazid[/eluser]
Dear All, what if i have added this line to my routes file, and it has no effect, i still have the default 404 error page when i write any thing after the domain name!? do you have any suggestions please
Thank you in advance!
#6

[eluser]Remko Posthuma[/eluser]
You have to define a valid route, so the function in the routed controller should exist. If the function doesn't exist the default error page will be shown.

Step1: Define the route "404_override" in your routes.php config file:
Code:
$route['404_override']             = "home/show_404";
Step 2: Open the controller and define a function show_404. In my case this will be the home.php controller
Code:
function show_404()
{
    $this->output->set_status_header('404');
    echo "404 - not found";
}
This should work :-)




Theme © iAndrew 2016 - Forum software by © MyBB