2017-10-28 174 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不客气 –