CodeIgniter global variable

后端 未结 4 848
无人共我
无人共我 2021-02-01 10:08

I am using $data in all my views $this->load->view(\'my_view\', $data);

I have also autoload a Controller following this guide Exten

4条回答
  •  长发绾君心
    2021-02-01 10:42

    1: Create MY_Controller in application/libraries with following:

    class MY_Controller extends Controller {  
      var $data;      
      //constructor function              
    }
    

    2: Replace Controller to MY_Controller in all your controller files and load views with $this->data

    class Contact extends Controller { //to.. } 
    
    class Contact extends MY_Controller { 
     $this->load->view('contact_view', $this->data);
    }
    

    this way you can perform default functions that are applicable for whole site in MY_Controller like loading settings.

提交回复
热议问题