access model from view in codeigniter?

前端 未结 9 1259
星月不相逢
星月不相逢 2020-12-20 13:30

can anyone tell me how do i access model from view in codeigniter?

相关标签:
9条回答
  • 2020-12-20 14:07

    You can use following code:

       $ci =&get_instance();
       $ci->load->model(your model);
       $ci->(your model)->(your function);     
       Note: You have to call your model in your controller.Its working fine
    
    0 讨论(0)
  • 2020-12-20 14:08

    You can access basicly a method from view in codeingiter.

    public function index()
    {
    
        $this->load->model('persons');
        $data['mydata'] = $this->persons->getAllSessionData();
        $this->load->view('test_page', $data);
    }
    

    in view

    print_r ($mydata);
    

    my function returned an array.

    0 讨论(0)
  • 2020-12-20 14:14

    Hey. You can access from view to models the same mode as you access on its controller. Remember that the view access to models that import its controller.

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