Polls

Which language do you use for website development?
 

Home Running a controller on 404 Error
Running a controller on 404 Error PDF
Written by Nirbhab Barat   
Monday, 13 July 2009 21:36

Few days back I was thinking, if CI could run a specific controller on 404 errors.
As we know there is a error template, already present.

But what if all the URLs are sent to this error controller……
This controller will check for a specific page in database and get the content for that page.

Here's a way to do so:

1. Go to system\libraries\Router.php

2. Go to the following function: _validate_request($segments)
initially it is:

if (file_exists(APPPATH.'controllers/'.$segments[0].EXT)){
return $segments;
}

3. Add elseif condition like this:

if (file_exists(APPPATH.'controllers/'.$segments[0].EXT)){
return $segments;
}elseif($segments[0]!='admin'){
define('ERROR_PAGE',TRUE,TRUE);
$segments[0]='error';//Controller
$segments[1]='index';//Function
return $segments;
}

Now on every 404-error page you can run a specific task, even can track the URLs which users have not found and look forward that, how he went there.

Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
Security
Please input the anti-spam code that you can read in the image.

!joomlacomment 4.0 Copyright (C) 2009 Compojoom.com . All rights reserved."

 
Follow me on twitter
View my LinkedIn profile