如何从控制器功能传递另一个数据,以显示codeigniter中同一视图中另一个功能的结果?

时间:2022-11-29 21:37:08

Example function to load view :

加载视图的示例函数:

function ringkas(){
        $data['artikel_uji']=$this->db->get('tb_artikel_uji')->result();
        $this->load->view('v_header');
        $this->load->view('v_data_uji',$data);      
    }

After I load this view..I fill form in this view and click submit.

Example view like this :

加载此视图后,我在此视图中填写表单,然后单击“提交”。像这样的示例视图:

<form action="<?php echo site_url()?>/c_index/hitung_knn" method="POST">
<input type="text" name="fill_your_name">
<input type="submit" name="process">
</form>

after that, the result after I submit I want to display in this view too..so I call function ringkas() again. but how can I display the result from function hitung_knn?

之后,我提交后的结果我也希望在这个视图中显示...所以我再次调用函数ringkas()。但是如何显示hitung_knn函数的结果呢?

Example output from function hitung_knn() :

函数hitung_knn()的示例输出:

function hitung_knn($id){
   $example= array('1','2','3','4','5');         
}

2 个解决方案

#1


1  

You might change to this:

你可以改成这个:

function ringkas( $example = array() ){
    $data['artikel_uji']=$this->db->get('tb_artikel_uji')->result();
    $data['example']=$example;
    $this->load->view('v_header');
    $this->load->view('v_data_uji',$data);      
}



function hitung_knn($id){
   $example= array('1','2','3','4','5');         
   $this->ringkas($example);
}

#2


1  

function ringkas(){
    if($_POST){
        /* pass either as post parameter or just argument of function like ringkas($id=0)*/
        $this->input->post('id');
        $data['something'] = $this->hitung_knn($id);
    }else{
        $data['artikel_uji']=$this->db->get('tb_artikel_uji')->result();

    }
    $this->load->view('v_header');
    $this->load->view('v_data_uji',$data);  
}

function hitung_knn($id){
    return array('1','2','3','4','5');         
}

<form action="<?php echo site_url()?>/c_index/ringkas" method="POST">
    <input type="text" name="fill_your_name">
    <input type="submit" name="process">
</form>

Make sure this is not the perfect code but you will get the idea from it. You just need to call function hitung_knn fromk inside ringkas. And change your form post url to ringkas.

确保这不是完美的代码,但你会从中得到这个想法。你只需要在ringkas中调用函数hitung_knn fromk。并将您的表单发布到ringkas。

#1


1  

You might change to this:

你可以改成这个:

function ringkas( $example = array() ){
    $data['artikel_uji']=$this->db->get('tb_artikel_uji')->result();
    $data['example']=$example;
    $this->load->view('v_header');
    $this->load->view('v_data_uji',$data);      
}



function hitung_knn($id){
   $example= array('1','2','3','4','5');         
   $this->ringkas($example);
}

#2


1  

function ringkas(){
    if($_POST){
        /* pass either as post parameter or just argument of function like ringkas($id=0)*/
        $this->input->post('id');
        $data['something'] = $this->hitung_knn($id);
    }else{
        $data['artikel_uji']=$this->db->get('tb_artikel_uji')->result();

    }
    $this->load->view('v_header');
    $this->load->view('v_data_uji',$data);  
}

function hitung_knn($id){
    return array('1','2','3','4','5');         
}

<form action="<?php echo site_url()?>/c_index/ringkas" method="POST">
    <input type="text" name="fill_your_name">
    <input type="submit" name="process">
</form>

Make sure this is not the perfect code but you will get the idea from it. You just need to call function hitung_knn fromk inside ringkas. And change your form post url to ringkas.

确保这不是完美的代码,但你会从中得到这个想法。你只需要在ringkas中调用函数hitung_knn fromk。并将您的表单发布到ringkas。