2010-01-20 12 views
5

Chcę, aby mój error_404.php pojawiał się w widokach szablonu mojej witryny. Rozszerzyłem klasy CI_Exceptions (MY_Exceptions) i zastąpiłem metody show_404() i show_error(). Teraz to, co chcę zrobić, to móc załadować tam plik widoku. Optymalnie, chciałbym załadować metody _header() i _footer() w klasie MY_Controller. Czy to w jakiś sposób jest możliwe?CodeIgniter - Używanie load-> view() w wyjątkach

class MY_Exceptions extends CI_Exceptions { 

    public function __construct(){ 
    parent::__construct(); 
    } 

    function show_404($page = '') 
    { 
     $heading = "404 Page Not Found"; 
     $message = "The page you requested was not found for some strange reason..."; 

     log_message('error', '404 Page Not Found --> '.$page); 

     $CI =& get_instance(); 
     $CI->load->view('template/header'); 
     echo $this->show_error($heading, $message, 'error_404', 404); 
     $CI->load->view('template/footer'); 
     exit; 
    } 

    function show_error($message, $status_code = 500) 
    { 
     $error =& load_class('Exceptions'); 
     echo $error->show_error('An Error Was Encountered', $message, 'error_general', $status_code); 
     exit; 
    } 
} 

Ale nie mogę tego zrobić. Jakieś sugestie?

+0

parent :: __ construct(); powinien być rodzicem: CI_Exceptions; – shin

+1

@shin - nie w PHP5, myślę. –

Odpowiedz

-1

Użyj tego w kontrolerze.

$data['main'] = 'my404'; 
$this->load->vars($data); 
$this->load->view('maintemplate'); 

I w widoku maintemplate.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 

what ever here. 


</head> 
<body> 
<div id="wrapper"> 
    <div id="header"> 
    <?php $this->load->view('admin_header');?> 
    </div> 

    <div id="main"> 
    <?php $this->load->view($main);?> 
    </div> 

    <div id="footer"> 
    <?php $this->load->view('admin_footer');?> 
    </div> 
</div> 


</body> 
</html> 

Utwórz widok my404.

+0

Jakiego kontrolera to on umieścił? Czy nadal musi rozszerzać obsługę wyjątków? – bafromca

+0

@BrettAlton, tak. Wygląda jednak na to, że to nie jest jasne – manix

Powiązane problemy