2014-07-23 79 views
1

我終於得到Codeigniter與點燃的數據表一起工作。現在我遇到了另一個問題。任何人都可以幫助或告訴我是否可以使用codeigniter的數據表插件運行下面的查詢。具有點燃數據表的Codeigniter

目前我是控制器,其是跛我知道內做它(這是僅用於測試)

控制器 $數據[「查詢」] = $這個 - > test_queries-> list_partners() ;

foreach($data['query'] as $k => $company){ 
     $data['query'][$k]->partner_contacts = $this->test_queries->get_partner_contacts($company->id); 
    } 

查詢示範

function list_partners(){ 
    $this->db->select("company.id,name,general_email,general_phone,market"); 
    $this->db->from("company"); 
    $this->db->join('markets','markets.id = company.market_id');   
    $query = $this->db->get();  
    $result = $query->result();  
    return $result; 
} 

function get_partner_contacts($id){ 

    $this->db->select('partner_contacts.id,contact_type'); 
    $this->db->from('partner_contacts'); 
    $this->db->where('company_id',$id);  
    $this->db->join('department','department.id = partner_contacts.contact_type_id');  
    $query = $this->db->get();  
    $result = $query->result();  
    return $result; 
} 

回答

1

您可以更改模型,如下疑問:

function list_partners(){ 
    $this->datatables->select("company.id,name,general_email,general_phone,market"); 
    $this->datatables->from("company"); 
    $this->datatables->join('markets','markets.id = company.market_id');   
    return $this->datatables->generate(); 
} 

function get_partner_contacts($id){ 

    $this->datatables->select('partner_contacts.id,contact_type'); 
    $this->datatables->from('partner_contacts'); 
    $this->datatables->where('company_id',$id);  
    $this->datatables->join('department','department.id = partner_contacts.contact_type_id');  
    return $this->datatables->generate(); 
} 

您還可以使用方法,如果您使用的是PHP 5以上鍊接。