簡體   English   中英

頁眉和頁腳不能在codeigniter中全局使用

[英]Header and Footer can't use globally in codeigniter

我是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視圖文件僅未加載頁眉和頁腳。

嘗試將方法更改為此:

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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM