CodeIgniter - Best way for checking true result

痞子三分冷 提交于 2019-12-30 11:33:08

问题


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

回答1:


try with these

// INSERT

$this->db->insert_id();

// UPDATE and DELETE

$this->db->affected_rows();

// SELECT

$this->db->num_rows();  


来源:https://stackoverflow.com/questions/10488151/codeigniter-best-way-for-checking-true-result

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!