Best method of including views within views in CodeIgniter

前端 未结 6 694
时光说笑
时光说笑 2020-11-28 02:57

I\'m starting a large codeigniter project and would like to try to create some reusable \'mini\' views for snippets of content like loops of data which may be displayed on d

6条回答
  •  清酒与你
    2020-11-28 03:47

    In my opinion for solve in more efficient way this problem I have done so:

    You create a new helper (in application/helpers) with name (es. common_helpers.php, the underscore is important). In this file, you put all the functions for example build pieces of html in common.

    In your controller you call only one view in respect of MVC and call the functions from your custom helper.

    class Hello extends CI_Controller {
    
       public function index(){
           $this->load->helper('common');
           $this->load->view('index');   
       }
    
    }
    

提交回复
热议问题