在codeigniter控制器功能中创建更好的多数据库方法

时间:2015-08-13 12:04:59

标签: php codeigniter model-view-controller

这个函数的更好/更清晰的方法是在codeigniter控制器中的不同数据库表中创建多个记录:

private function newConcern($data) {
    $this->load->model('customer_model', 'customer');
    $this->load->model('complaints_dealers_model', 'dealer');
    $this->load->model('vehicle_model', 'vehicle');
    $this->load->model('complaints_vehicles_model', 'complaints_vehicles');
    $this->load->model('complaints_emails_model', 'emails');

    // create customer record
    $this->customer->create($data['customer']);

    // create concern record
    $this->create($data['concern']);

    // create dealer record
    $this->dealer->create($data['dealer']);

    // create vehicle record
    $this->vehicle->create($data['vehicle']);

    // create complaint vehicle record
    $this->complaints_vehicles->create($data['complaint_vehicle']);

    // check whether we have any email recipients
    if (!empty($data['department']) || !empty($data['recipients'])) {
        // process branch email
        $this->emails->processBranchEmail($data, $concern->id);
    }

    return true;
}

尽管需要进行所有函数调用,但感觉这个函数还有太多功能。

有关更好方法的任何建议吗?

0 个答案:

没有答案