问题与笨保存的更新信息(Issue with saving an update informatio

2019-11-03 03:49发布

我的目标是更新job_contract。 有迹象表明,应该是这样的两种方式。 1.通过客户端的页面,并通过2提供商的页面。

我现在已经是我的工作模式是:

 public function update_job_contract($post_obj)
{
    $id = $post_obj['id'];
    $data = array 
    (
        'client_feedback' => $post_obj['client_feedback'],
        'client_notetoself' => $post_obj['client_notetoself'],
        'contract_status' => $post_obj['contract_status'],
        'client_id' => $this->auth_model->get_user_id()
    );

    $this->db->insert('job', $data);
}

public function provider_update_job_contract($post_obj)
{
    $id = $post_obj['id'];
    $data = array 
    (
        'provider_feedback' => $post_obj['provider_feedback'],
        'provider_notetoself' => $post_obj['provider_notetoself'],
        'provider_id' => $this->auth_model->get_user_id()
    );

    $this->db->insert('job', $data);
}

我有我的客户机控制器页面下面几行:

public function update_job_contract() 
{
    $this->validateRole('client');
    $this->load->model('job_model');

    $id = $this->uri->segment(3,0);


    $data['job'] = $this->job_model->get_job($id);  

    $this->load->view('client/update_job_contract', $data);
}   

public function update_job_contract_submit() 
{
    $this->validateRole('client');
    $this->load->model('job_model');

    if ( '0' == $_POST['id'] ) {
    $this->job_model->update_job_contract($_POST);
    //} 
    redirect('client/manage_job_contracts?message=Congratulations!');
}

这在我的供应商控制器页面:

 public function provider_update_job_contract() 
{
    $this->validateRole('provider');
    $this->load->model('job_model');

    $id = $this->uri->segment(3,0);


    $data['job'] = $this->job_model->get_job($id);  

    $this->load->view('provider/provider_update_job_contract', $data);
}   

public function provider_update_job_contract_submit() 
{
    $this->validateRole('provider');
    $this->load->model('job_model');

    if ( '0' == $_POST['id'] ) {
    $this->job_model->provider_update_job_contract($_POST);
    } 
    redirect('provider/job_contracts?message=Congratulations!');
}

问题是,他们没有真正更新的条目。 请帮忙..

Answer 1:

您正在使用$this->db->insert()但活动记录进行更新,你应该使用行$this->db->update()

$data = array(
   'title' => $title,
   'name' => $name,
   'date' => $date
);

$this->db->where('id', $id);
$this->db->update('mytable', $data);

换句话说你的职责应该是这样的:

public function update_job_contract($post_obj)
{
    $id = $post_obj['id'];
    $data = array 
    (
        'client_feedback' => $post_obj['client_feedback'],
        'client_notetoself' => $post_obj['client_notetoself'],
        'contract_status' => $post_obj['contract_status'],
        'client_id' => $this->auth_model->get_user_id()
    );
    $this->db->where('id', $id);
    $this->db->update('job', $data);
}

public function provider_update_job_contract($post_obj)
{
    $id = $post_obj['id'];
    $data = array 
    (
        'provider_feedback' => $post_obj['provider_feedback'],
        'provider_notetoself' => $post_obj['provider_notetoself'],
        'provider_id' => $this->auth_model->get_user_id()
    );
    $this->db->where('id', $id);
    $this->db->update('job', $data);
}

此外,控制器$ _POST内部应与这 - $>输入 - >交的更换()

使用这个作为一个例子:

public function provider_update_job_contract_submit() 
{
    $this->validateRole('provider');
    $this->load->model('job_model');

    $post = $this->input->post();
    if ( '0' == $post['id'] )
    {
        $this->job_model->provider_update_job_contract($post);
    } 
    redirect('provider/job_contracts?message=Congratulations!');
}

确保您以同样的方式更新其他控制器



文章来源: Issue with saving an update information in Codeigniter