2017-10-28 179 views
0

有沒有辦法在plates php中,我可以在控制器中創建模板,但使用其他控制器進行渲染。假設我有兩個控制器。 HeaderController和一個SearchController。有沒有一種方法來製作模板,但不能在板中呈現php

SearchController

class Search extends \system\core\BaseController 
{ 
    public function Index() 
    { 
     $data['text_search'] = 'Search..'; 

     // This $this->template->render down below is what I don't want now 
     // okay asign the data but do not display the template yet 
     echo $this->template->render('common/search', $data); 
    } 
} 

假人SearchController應指派$數據到模板search.tpl,但不顯示/顯示模板。

這是我將調用上述控制器

HeaderController

class HeaderController extends \system\core\BaseController 
{ 
    public function Index() 
    { 
     // Some codes 

     // Call/load the SearchController and asign it to $data['search'] 
     $data['search'] = $this->load->controller('common/SearchController'); 

     // and then pass all $data and render/display it. 
     echo $this->template->render('common/header', $data); 
    } 
} 

有沒有做這件事的呢?

回答

1

這個問題實際上來自於您在課堂上使用echo的事實。如果你的「控制器」(好吧,他們實際上似乎是視圖和控制器的組合)分別是return的內容或Response類的實例,那麼你的問題應該會消失。

+0

tereško,男人..這是愚蠢的。謝謝哥們,回報有幫助。 – Mecom

+0

@Mecom不客氣 –