在plates php中是否有办法可以在控制器中创建模板,但使用其他控制器渲染模板。说我有两个控制器。 HeaderController和SearchController。
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应该将$ data分配给模板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);
}
}
有办法吗?
答案 0 :(得分:1)
The issue actually comes from the fact, that you are using echo
within your class. If your "controllers" (well, they actually seem to be a combination of view and controller) were to return
either the content or Response
class instance, then you problem should disappear.