2016-05-30 26 views
0

看來,庫安裝正確,因爲我可以用title()set_partial()set_layout設置標題。而且一切正常。但我無法傳遞任何數據。將數據傳遞到視圖安裝<a href="https://github.com/philsturgeon/codeigniter-template" rel="nofollow">Phil Sturgeon Codeigniter Template library</a></p> <p>菲爾鱘魚笨模板庫

如果我在控制器設定新的冠軍$this->template->title('My Title'); 我可以輕鬆地獲得冠軍,任何視圖與echo $template['title']

例如,我想傳遞一個信息:
在View:

<?php echo $template['message']; ?> 

In Controller I試試:

$this->template->set('message', 'My new mess'); 
$this->template->build('dashboard'); 
// I get *Undefined index: message* from View 


$data['message'] = ['My new mess']; 
$this->template->build('dashboard', $data); 
// Same *Undefined index: message* 


$this->template->build('dashboard', array('message' => 'My new mess')); 
// Even this does not work 


使用CI 3. 模板關於解析器配置設置:

$config['parser_enabled'] = FALSE; 
$config['parser_body_enabled'] = FALSE; 

看來我錯過一個小細節。

回答

0

最後我想通了。

我自己的主要困惑來自文檔本身。 只有模板設置的標題可以在視圖中調用$this->template->title()作爲$template['title']

所有其他數據傳遞如下

在控制器:

$this->template->set('message', 'My message'); 
$this->template->build('dashboard'); 

在查看剛:

echo $message 
+0

要知道,5歲的代碼,並仔細檢查它的所有方法。 – Tpojka

+0

到目前爲止沒有CI 3.0.6的問題。其實我很驚訝,可能最流行的模板庫在4年內沒有任何更新。儘管我沒有使用CI解析器進行嘗試。 – ProgZi

相關問題