سؤال

I tried some of the steps here, but until now, my edit and delete functions do not work correctly. Can you please help me with it?

First, I have these lines in my client controller:

public function edit_job
{

    $this->validateRole('client');
    $this->load->model('job_model');

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

    $data['my_preference'] = $this->array_to_select( $this->job_model->get_all_categories(), 'id','name');
    $data['job'] = $this->job_model->get_job($id);
    $this->load->view('client/edit_job', $data);
}

public function delete_job() 
{

    $this->validateRole('client');
    $this->load->model('job_model');

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

    $this->job_model->delete_job($id);
    //echo '<script language="javascript">alert("Post successfully deleted.");</script>';
    redirect('client/manage_jobs?message=Job post successfully deleted');

}
}

Then, I have these lines in my job_model

function edit_job() 
{
    $data = array(
        'title' => $this->input->post('title'),
        'category_id' => $this->input->post('category_id'),
        'start_date' => date("m-d-Y", strtotime($this->input->post('start_date'))),
        'description' => $this->input->post('description'),
    );
    $this->db->where('id', $this->input->post('id'));
    $this->db->update('job', $data);

}
function delete_job($id) 
{
    $this->db->where('id', $id);
    $this->db->delete('job', $data);
}

Currently, add job works quite well (although I sometimes have problem with the start date), but edit and delete do not work well. Whenever I press edit in my view page, it will show a page exactly similar to a new add_job page (so whenever I type and fill in the form, it will be added as a new job, not as a revision of a particular job) (I've been trying to echo the original values first before editing can be done, but it never worked. In terms of delete job, it does show the redirect message, but whenever I check the jobs available, the supposedly deleted job is still available.

I have been stuck here for quite some time now. Please help me..

هل كانت مفيدة؟

المحلول

I think asp_tags is disable in your php settings. Change your code as following:

<?php echo $this->uri->segment(3, 0); ?>

instead of

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


and about delete, you don't need to pass second parameter in delete function. So do following:

$this->db->delete('job');

instead of

$this->db->delete('job', $data);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top