How to call codeigniter controller function from view

后端 未结 14 1740
小蘑菇
小蘑菇 2020-11-27 05:53

How to call codeigniter controller function from view? When i call the function in a controller, get a 404 page.

14条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 06:49

    We can also pass controller function as variable in the view page.

    class My_controller extends CI_Controller {
        public function index() {
               $data['val']=3;
               $data['square']=function($val){
                                   return $val*$val;
                                       };
        $this->load->view('my-view',$data);
    }
    }
    

    In the view page

    Square of

    The output is 9

提交回复
热议问题