将视图传递给MVC中的控制器?

时间:2014-09-15 15:30:21

标签: codeigniter

控制器:

function past_event(){

    $this->load->model('usermodel');
    $data = $this->usermodel->past();
    $this->load->view('past_event',$data); 

}

查看:

<p> <h4> Welcome to Past Events </h4> </p>
<?php     foreach($res->result_array() as $row){

        $ev_name = $row['ev_name']; 
        $image = $row['ev_image'];
        $start = $row['start'];
        $end = $row['end'];
        $desc = $row['ev_desc'];
        $ev_id  = $row['ev_id'];


        $res = array( 'ev_name' =>  $ev_name,
                      'ev_image' => $image,
                      'start' => $start,
                      'end' =>  $end,
                      'ev_desc' => $desc
                      );    
}
?>

1 个答案:

答案 0 :(得分:0)

更改您的控制器

function past_event(){

    $this->load->model('usermodel');
    $data['res'] = $this->usermodel->past();
    $this->load->view('past_event',$data); 

}

并使用此代码在您的视图中查看结果

<?php     foreach($res as $obj){

        echo $obj->ev_name.'--'.$obj->ev_image.'--'.$obj->start.'--'.$obj->end.'--'.$obj->ev_desc.'--'.$obj->ev_id;
        echo '<br><br>';
       }

?>