简体   繁体   中英

Codeigniter with Ignited Datatables

I have finally got Codeigniter to work with ignited datatables. Now i have run into a different problem. Can anyone help or tell me if i could run the below query with the datatables plugin for codeigniter.

At present i'm doing it within the controller which is lame i know (this was only for testing)

Controller $data['query'] = $this->test_queries->list_partners();

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

Queries in the Model

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;
}

You can change the queries in the model as below:

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();
}

You can also use method chaining if you are using PHP 5 or above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM