CodeIgniter - Calling a function from inside a view

后端 未结 7 1577
长情又很酷
长情又很酷 2021-01-06 13:25

Is it possible to call a function which is located in a controller from a view?

This is what i have in my controller, as an example

function checkKey         


        
7条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-06 14:20

    Your controller should pass a set of data to your view.

    Your view can then test if something is set and then act accordingly.

    $this->data['my_setting']='value';
    $this->load->vars($this->data);
    $this->load->view('your_view');
    

    Then in your view:

    if(isset($my_setting)){
      do something with my_setting
    }
    

提交回复
热议问题