user1257255
user1257255

Reputation: 1171

CodeIgniter - Best way for checking true result

What’s the best way for checking if some method in model or anywhere else was correctly carried out?

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);
}  

Upvotes: 1

Views: 2498

Answers (1)

Moyed Ansari
Moyed Ansari

Reputation: 8461

try with these

// INSERT

$this->db->insert_id();

// UPDATE and DELETE

$this->db->affected_rows();

// SELECT

$this->db->num_rows();  

Upvotes: 6

Related Questions