2010-01-20 14 views
5

Desidero che il mio error_404.php venga visualizzato nelle visualizzazioni del modello del mio sito. Ho esteso la classe CI_Exceptions (MY_Exceptions) e ho sovrascritto i metodi show_404() e show_error(). Ora quello che voglio fare è essere in grado di caricare un file di visualizzazione lì. In modo ottimale, vorrei caricare i metodi _header() e _footer() nella classe MY_Controller. Questo è possibile in qualche modo?CodeIgniter - Uso load-> view() in Exceptions

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; 
    } 
} 

Ma io non posso fare questo. Eventuali suggerimenti?

+0

parent :: __ construct(); dovrebbe essere padre :: CI_Exceptions; – shin

+1

@shin - non in PHP5, penso. –

risposta

-1

Utilizzare questo nel controller.

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

E nella visualizzazione 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> 

E crea la tua vista my404.

+0

Quale controller deve inserire? Ha ancora bisogno di estendere il gestore delle eccezioni? – bafromca

+0

@BrettAlton, si. Tuttavia, sembra che questo non sia davvero chiaro – manix