2控制器可以加载相同的视图页面吗?

时间:2014-09-18 09:29:25

标签: codeigniter

控制器1:

function view($ev_id){                 
     $this->load->model('usermodel');

     $data = $this->usermodel->act_join($ev_id);            
     //print_r($total);
     foreach($data->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'];
        $id= $row['id'];
      }

      $data = array( 'ev_name' =>  $ev_name,
                      'ev_image' => $image,
                      'start' => $start,
                      'end' =>  $end,
                      'ev_desc' => $desc,
                      'ev_id' => $ev_id,
                      'id'  => $id                          
                   );  
       $this->load->view('view_event',$data);
}

如何将多个值传递给视图

控制器2:

function check() {

     $this->load->model('usermodel');
     $query = $this->usermodel->join($ev_id);
     print_r($query)
     $this->load->view('view_event',$query);
}
  

2控制器可以加载相同的视图页

1 个答案:

答案 0 :(得分:0)

你正在做出重大误解 何时将数据传递给视图,您需要创建数组 例如 你有阵列

$data['test']= array( 'ev_name' =>  $ev_name,
                      'ev_image' => $image,
                      'start' => $start,
                      'end' =>  $end,
                      'ev_desc' => $desc,
                      'ev_id' => $ev_id,
                      'id'  => $id                          
                   );
  $this->load->view('view_event',$data);

现在在视图中可以获取数组的所有值

<?php echo $test ;?>

尝试和宾果游戏