2016-10-21 76 views
0

我在我的模型中有兩個函數,我想在我的模型中調用其他模型,但實際上是將錯誤數組轉換爲字符串。 這是我的代碼:如何在一個模型中調用其他模型?

public function get_detail_activity() 
{ 
    $status=$activity;//call function model activity 
    $query=$this->db->query("SELECT 
    t_trx_activity.activity_id FROM t_trx_activity 
    JOIN t_trx_activity_detail ON 
    t_trx_activity_detail.activity_id =t_trx_activity.activity_id 
    WHERE t_trx_activity.activity_id = '".$status."' //function put here"); 

    if($query->num_rows()>0) 
    { 
     return $query->result(); 
    } 
    else 
    { 
     return array(); 
    } 

public function activity() 
{ 
    $query=$this->db->query("SELECT t_trx_activity.activity_id 
     FROM t_trx_activity 
     ORDER BY 
     t_trx_activity.activity_id DESC LIMIT 1"); 
    $nik=$this->session->userdata('nik'); 

    if($query->num_rows()>0) 
    { 
     return $query->result(); 
    } 
    else 
    { 
     return array(); 
    } 
} 

如何調用函數等模型在一個模型?

+0

我不遵守你正試圖在這裏做...你能有另一個去試圖解釋你想要什麼實現? – TimBrownlaw

+0

我想要顯示來自get_detail_activity的數據和其中(來自函數活動) –

+0

因此,這是相同的模型還是不同的模型? –

回答

0

你沒有正確調用該函數,請嘗試以下,

public function get_detail_activity() 
{ 
    $status= $this->activity();//call function model activity 
    $query=$this->db->query("SELECT 
      t_trx_activity.activity_id FROM t_trx_activity 
      JOIN t_trx_activity_detail ON 
      t_trx_activity_detail.activity_id =t_trx_activity.activity_id 
      WHERE t_trx_activity.activity_id = '".$status."'"); 
    if($query->num_rows()>0) 
    { 
     return $query->result_array(); 
    } 
    else 
    { 
     return array(); 
    } 
} 


public function activity() 
{ 
    $query=$this->db->query("SELECT t_trx_activity.activity_id 
     FROM t_trx_activity 
     ORDER BY 
     t_trx_activity.activity_id DESC LIMIT 1"); 
     $nik=$this->session->userdata('nik'); 

    if($query->num_rows()>0) 
    { 
     return $query->row()->activity_id; 
    } 
    else 
    { 
     return 0; 
    } 
} 
+0

錯誤數組到字符串轉換 –

+0

在哪行?我很確定錯誤還顯示行號? –

+0

@ i.one:檢查我更新的ans –

相關問題