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

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

#2
[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);
?>

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

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

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

thanks

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

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

#8
[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

#9
[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');
}




Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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