【问题标题】:Header and Footer can't use globally in codeigniterHeader 和 Footer 不能在 codeigniter 中全局使用
【发布时间】:2015-07-09 10:58:16
【问题描述】:

我是 codeigniter 的新手,我被称为所有页面的页眉和页脚。

为此,我在 application/core/MY_Loader.php 中创建了一个新文件

class MY_Loader extends CI_Loader {

    public function template($template_name, $vars = array(), $return = FALSE) {
        if ($return):
            $content = $this->view('header', $vars, $return);
            $content .= $this->view($template_name, $vars, $return);
            $content .= $this->view('footer', $vars, $return);

            return $content;
        else:
            $this->view('header', $vars);
            $this->view($template_name, $vars);
            $this->view('footer', $vars);
        endif;
    }

}

控制器:

$this->load->template('welcome_message', $data);

我必须做什么,才能在所有页面中获取页眉和页脚?

目前我的welcome_message 视图文件只加载而不加载页眉和页脚。

【问题讨论】:

  • 查看link
  • 是的。我使用了他们接受的相同代码。

标签: php codeigniter


【解决方案1】:

尝试将您的方法更改为:

public function template($template_name, $vars = array(), $return = FALSE) {
    if ($return):
        $content = $this->load->view('header', $vars, $return);
        $content .= $this->load->view($template_name, $vars, $return);
        $content .= $this->load->view('footer', $vars, $return);

        return $content;
    else:
        $this->load->view('header', $vars);
        $this->load->view($template_name, $vars);
        $this->load->view('footer', $vars);
    endif;
}

【讨论】:

    猜你喜欢
    • 2019-03-11
    • 2015-12-04
    • 1970-01-01
    • 1970-01-01
    • 2021-11-09
    • 2012-04-27
    • 1970-01-01
    • 2021-03-22
    • 2020-06-21
    相关资源
    最近更新 更多