CodeIgniter Forums
How to load view in file error_404.php? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How to load view in file error_404.php? (/showthread.php?tid=10610)



How to load view in file error_404.php? - El Forum - 08-06-2008

[eluser]Unknown[/eluser]
Hello!
At the beginning sorry for my English, but I learn his yet.

I have small problem with CodeIgniter. I would like to load view in file errors/error_404.php. So I put in this file code:
Code:
<?php
header("HTTP/1.1 404 Not Found");

$this->CI =& get_instance();
$this->data['main'] = $this->CI->load->view('404', array(), TRUE);
$this->CI->load->view('main', $this->data);
?>

If i visit on page www.mysite.pl/controller/qwerty (qwerty is any string) all works good. However when I go on page www.mysite.pl/qwerty I have error:
Quote:Fatal error: Call to undefined function get_instance() in .../application/errors/error_404.php on line 4

Please help me solve my problem.

Greetings from Poland,
Paul.


How to load view in file error_404.php? - El Forum - 08-06-2008

[eluser]abmcr[/eluser]
Have you try with
Code:
<?php
header("HTTP/1.1 404 Not Found");
$CI =& get_instance();
#$this->CI =& get_instance();
$this->data['main'] = $CI->load->view('404', array(), TRUE);
$CI->load->view('main', $this->data);
?>



How to load view in file error_404.php? - El Forum - 08-06-2008

[eluser]Pascal Kriete[/eluser]
Missing controller 404 errors are thrown before the CI super-object is instantiated. The function get_instance doesn't exist that early in the execution cycle. There are no satisfying workarounds to this problem yet Sad .


How to load view in file error_404.php? - El Forum - 09-07-2008

[eluser]supahero[/eluser]
that's why i cann't use it. even i have modified on system/codeigniter/Common.php at function function show_404() it still blank to load->view()

any luck?


How to load view in file error_404.php? - El Forum - 10-10-2008

[eluser]supahero[/eluser]
any body help this problem?
admin please see this thread.

thanks


How to load view in file error_404.php? - El Forum - 03-03-2009

[eluser]Banana Man[/eluser]
Why dont you just include the files needed, i presume it is mainly static content you'll require, and simply just including files maybe the easiest option ?


How to load view in file error_404.php? - El Forum - 03-03-2009

[eluser]Banana Man[/eluser]
Code:
<?php

header("HTTP/1.1 404 Not Found");
require_once(path to file needed);
require_once(path to file needed);
require_once(path to file needed);

Just use native php if the system isnt completely initiated yet, also you could develop this further to send yourself an email when these errors occur with $heading and $message


How to load view in file error_404.php? - El Forum - 03-03-2009

[eluser]Banana Man[/eluser]
remember that path to file will be relative to where index.php is placed, for example ../application/views/_global_nav.php


How to load view in file error_404.php? - El Forum - 07-06-2012

[eluser]Unknown[/eluser]
In 'application/config/routes.php' just specify the controller and function to be called on a 404.

routes.php
----------
Code:
$route['404_override'] = 'site/not_found';

Using the above example just put a function called 'not_found' in the controller 'site.php'.
Then just load the view you want as usual.

site.php
--------
Code:
public function not_found()
{
$this->load->view('error_404');
}