douzi7219 2014-07-04 01:06
浏览 55

从视图中调用函数

I need to know how I can call a controller function from view,here is the code,there a some few examples but I couldn't understand,

controller

<?php

class Site2 extends CI_Controller{

 public function account_details($id){
        $this->load->model('bank_account_model');
        $data['ac_results'] = $this->bank_account_model->getAccount();
        $this->load->view('view_header');
        $data['results'] = $this->get_company_model->get_All();
        $this->load->view('view_nav',$data);
        $this->load->view('bank_account_detais.php');
        $this->load->view('view_footer');
    }

}

from the view I need to call acccount_detail function with parameters,

  • 写回答

1条回答 默认 最新

  • dplece1882 2014-07-04 02:16
    关注

    It is really best to NOT call a function from a view, but if you insist, you have several options.

    1) You can create a helper (as suggested by xd6_), then load the helper before invoking the view(s).

    2) You can put the function in the model and pass the model to the view--similar to how you sent $data to the view_nav view.

    3) You can call the function before invoking the view and pass the result to the view, again similar to how you send $data.

    4) You can add the function NOT as a member of you controller, but still defined in the the same file as your controller. (I'm not claiming this is a good practice, but it can be done.)

    评论

报告相同问题?