2014-09-12 143 views
-2

控制器:值传递给在codeignitor控制器

function active_event() { 
    $this->load->view('active_event'); 
    $a = $this->load->model('Usermodel');  
} 

型号:

function active() { 

    $query = $this->db->query(" SELECT * from event WHERE start > FORMAT(Now(),'MM-DD-YYYY') AND end < FORMAT(Now(),'MM-DD-YYYY')"); 

    foreach($query->result_array() as $row){ 

     $image = $row['image']; 
     $mobile = $row['mobile']; 
     $email = $row['email']; 
     $country = $row['country']; 
     $id = $row['id']; 
     $this->session->set_flashdata('id', $id); 
    } 

    $data = array('name' => 'name', 
       'image' => 'image', 
       'mobile' => 'mobile', 
       'email' =>'email', 
       'country' =>'country', 
       'id'=> 'id' 
       ); 

     return $data; 
} 
+1

什么是这个问题? – Dexa 2014-09-12 13:30:55

回答

0

您需要使用您在模型中创建的函数,然后将它传递给用这种方式查看:

function active_event() { 
    //Load model 
    $this->load->model('Usermodel');  

    //Call model function and save it to $data['a'] 
    $data['a'] = $this->usermodel->active(); 

    //Pass the $data array to the view - in the view you will be able to use $a 
    $this->load->view('active_event', $data); 
}