2013-05-02 102 views
0

嗨,大家好,我在加載多個視圖的代碼中遇到了問題。在Codeigniter中加載視圖

$this->load->view('header'); 
$this->load->view('body-view', $data); 
$this->load->view('footer'); 

上面的代碼將允許我在其他服務器上正確地加載視圖。出於某種原因,我的服務器一次只能輸出其中一個視圖。我已經使用codeigniter幾年了,所以我知道這是有效的語法。

它可能是我的服務器配置輸出問題?任何幫助深表感謝。

+0

您是否已驗證所有視圖在單獨調用時是否完全無錯地加載? – user20232359723568423357842364 2013-05-02 02:39:31

+0

我已檢查過每個單獨的視圖 – user2341407 2013-05-02 02:49:11

+0

您的編碼器核心文件必須存在問題。 – 2018-02-26 05:20:50

回答

0

而是嘗試這種方法

$view = $this->load->view('header',array(),TRUE); 
$view .= $this->load->view('body-view', $data , TRUE); 
$view .= $this->load->view('footer',array(),TRUE); 

echo $view; 

另外,請檢查你的HTML了Syntex它可能加載多個視圖時會造成問題。請驗證您的html並再試一次。

+0

你爲什麼認爲這與他試圖做的不同? – 2013-05-07 03:55:09

1

我解決了這個問題。一些我怎麼猜的代碼包必須已經損壞。我剛剛重新配置codeigniter與新的下載版本,我的代碼完美工作。

0
I guess you are not passing true parameter while passing view file. 
please refer bellow tricks: 
$output = $this->load->view('your_view', 'your_data', true); 
$output .= $this->load->view('your_other_view', 'your_other_data', true); 
$output .= $this->load->view('your_last_view', 'your_last_data', true); 
$this->output->set_output($output); 

**Second Method, you can be passing view with data like :** 
$data['header'] = $this->load->view('your_header_view_file_name', true); 
$data['footer'] = $this->load->view('your_footer_view_file_name', true); 
$data['your_necessary_data'] = $your variables ; 
$data['your_necessary_data2'] = $your variables ;  
$this->load->view('blogview',$data);