How to create a hyperlink to a controller method and include a parameter using CodeIgniter
20:08 06 Jul 2020

I have a project on CodeIgniter. I want to delete the data from database. If a user clicks a delete button, the row should be deleted in the database.

my problem I think all code is working, but I think id is not getting in my controller.

There is no error, but data is also not deleting from database.

offerfetch.php(view)

Delete

update

admin.php(controller)

public function delarticles()
{
    $id = $this->input->get('offer_id');
    $this->load->model('adminloginmodel');
    if ($this->adminloginmodel->del($id)) {
        $this->session->set_flashdata('insertsuccess','Delete Successfully');
        $this->session->set_flashdata('msg_class', 'alert-success');
    } else {
        $this->session->set_flashdata('insertsuccess', 'Please try again..not delete');
        $this->session->set_flashdata('msg_class', 'alert-danger');
    }
    return redirect('admin/viewoffers');
}

in order to debug, I have used:

print_r($id);
exit();

after the line $id=$this->input->get('offer_id'); in a controller but I'm not getting any id, blank page is coming up.

adminloginmodel.php(model)

public function del($id)
{
    return $this->db->delete('offers', ['offer_id' => $id]);
}
php codeigniter hyperlink