having a fixed view across all controllers in Codeigniter

后端 未结 2 1045
清酒与你
清酒与你 2021-01-21 13:05

For loading the views in CodeIgniter, I have to repeat loading the fixed views (header and footer) which is a little annoying to be repeated for every view-related controller.

相关标签:
2条回答
  • 2021-01-21 13:42

    try this library, it worked for me, when I used it

    https://github.com/philsturgeon/codeigniter-template

    0 讨论(0)
  • 2021-01-21 14:01

    You can do with library.

    Create a new library file called template.php and write a function called load_template. In that function, use above code.

    public function load_template($view_file_name,$data_array=array()) {

    $ci = &get_instatnce();

    $ci->load->view("header");

    $ci->load->view($view_file_name,$data_array);

    $ci->> load->view("footer");

    }

    You have to load this library in autoload file in config folder. so you don't want to load in all controller.

    You can this function like

    $this->template->load_template("index");

    If you want to pass date to view file, then you can send via $data_array

    0 讨论(0)
提交回复
热议问题