0


I am tring to create default controller for no matter what URL you access to.
Meaning, custom 404.

class MY_Exceptions extends CI_Exceptions
{
var $ci;

public function __construct()
{
    parent::CI_Exceptions();
    $this->ci =& get_instance();
}

function show_404($page = '')
{
  //load view here

}

}

I am getting get_instance is undefined. (because it was defined after the libraries get called)
Is there a way to create custom 404 controller in codeignigter 1.7.2 without playing with the system core code.

Thanks

1
  • "Because it was defined after the libraries get called" does not make sense. If it was defined /after/ it should be ok. Commented Dec 21, 2010 at 16:12

4 Answers 4

2

Upgrade to CodeIgniter 2.0 because its stable and use:

$route['404_override'] = '';
Sign up to request clarification or add additional context in comments.

Comments

1

If you just want to customize the 404 page, you can do so under the /system/application/errors/error_404.php page. The one caveat with this is that you can't use the $this object, it's strictly HTML/CSS or built-in PHP (no access to your libraries, models, etc.).

This is the page that CodeIgniter will display by default when it can't find a controller to handle a request.

Not sure if that's why you're trying to do or not, but that would be the simplest way to create a custom 404 page.

3 Comments

+1 assuming this is what OP wants, why bother reinventing the wheel
Thanks, I need A Controller and not HTML.
You could always put redirect('controller/function') into the errors/error_404.php page.
0

http://maestric.com/doc/php/codeigniter_404

i have used this solution and it works for me in CI 1.7

Comments

0

This should work fine. Make sure it's in the 'application/libraries' folder, and make sure your config has 'MY_' set as the custom library name.

Also, if you are doing function __construct(){}, you can do parent::__construct().

1 Comment

I did what you explained, this is not working... Any other way to create Custom CONTROLLER(!) for 404? Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.