【问题标题】:is there a way to make template but not render it in plates php有没有办法制作模板但不在plate php中渲染它
【发布时间】:2017-10-28 20:43:07
【问题描述】:

plates php 中有没有一种方法可以让我在控制器中制作模板,但使用另一个控制器渲染它。假设我有两个控制器。 HeaderController 和 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);
    }
}

有办法吗?

【问题讨论】:

    标签: php templates model-view-controller plates


    【解决方案1】:

    问题实际上来自这样一个事实,即您在课堂上使用echo。如果您的“控制器”(嗯,它们实际上似乎是视图和控制器的组合)是 return 内容或 Response 类实例,那么您的问题应该会消失。

    【讨论】:

    • tereško,伙计..那是愚蠢的。谢谢哥们,退货有帮助。
    猜你喜欢
    • 1970-01-01
    • 2014-05-26
    • 2018-07-30
    • 2012-04-28
    • 2016-12-03
    • 2016-08-23
    • 1970-01-01
    • 2023-03-29
    • 2016-08-01
    相关资源
    最近更新 更多