• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to load view in file error_404.php?

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:
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,

Have you try with
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);

[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 .

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?

any body help this problem?
admin please see this thread.


[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 ?

[eluser]Banana Man[/eluser]

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

[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

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

$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.

public function not_found()

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.