CodeIgniter is the best way to verify true results.

What is the best way to check if any method is executed correctly in the model or elsewhere?

Is this a good way?

Model:

$data['field1'] = $this->input->post('field1');
$data['field2'] = $this->input->post('field2');
$data['field3'] = $this->input->post('field3');

if ($this->db->insert('table', $data))
{
   return TRUE;
}
else
{
   return FALSE;
} 

Controller:

if ($this->form_validation->run() == FALSE)
{
    $this->load->view('page_view', $data);
}
else
{
    if ($this->Model->Insert_data())
    {
       $this->session->set_flashdata("insertsuccess", TRUE);
    }
    else
    {
       $this->session->set_flashdata("inserterror", TRUE);
    }
    $this->load->view('page_view', $data);
}  
+1
source share
1 answer

try with these

// INSERT

$this->db->insert_id();

// UPDATE and DELETE

$this->db->affected_rows();

// SELECT

$this->db->num_rows();  
+6
source

All Articles